Skip to content

Commit

Permalink
Add upload_sp_items() function
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Jun 24, 2024
1 parent 41743a7 commit 6205f02
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export(sp_url_parse_path)
export(sp_url_parse_query)
export(update_sp_list_item)
export(upload_sp_item)
export(upload_sp_items)
export(write_sharepoint)
import(rlang)
importFrom(Microsoft365R,get_sharepoint_site)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sharepointr (development version)

* Add `upload_sp_items()` function (2024-06-24).

# sharepointr 0.1.0

* Initial version.
82 changes: 82 additions & 0 deletions R/write_sharepoint.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#' @noRd
sp_url_as_src_dest <- function(url, src, call = caller_env()) {
sp_url_parts <- sp_url_parse(url, call = call)
file_path <- sp_url_parts[["file_path"]] |>
str_remove_slash()

str_c_url(file_path, basename(src))
}

#' Write an object to file and upload file to SharePoint
#'
#' @description
Expand Down Expand Up @@ -166,6 +175,79 @@ upload_sp_item <- function(file = NULL,
}
}

upload_sp_src(
src = src,
dest = dest,
drive = drive,
overwrite = overwrite,
blocksize = blocksize,
recursive = recursive,
parallel = parallel,
call = call
)
}

#' @rdname upload_sp_item
#' @export
upload_sp_items <- function(file = NULL,
dest,
...,
src = NULL,
call = caller_env()) {
if (!is_character(src)) {
if (!is_character(file)) {
cli_abort(
"One of {.arg file} or {.arg src} must be a character vector",
call = call
)
}

src <- file
}

check_character(file, call = call)

if (is_url(dest) && has_length(dest, 1)) {
dest <- map_chr(
src,
\(x) {
sp_url_as_src_dest(
url = dest,
src = x
)
}
)
}

dest <- vctrs::vec_recycle(
dest,
size = length(src)
)

dest_list <- map2_chr(
src, dest,
\(x, y) {
upload_sp_src(
src = x,
dest = y,
...,
call = call
)
}
)

invisible(dest_list)
}

#' @noRd
upload_sp_src <- function(src,
dest = NULL,
drive = NULL,
blocksize = 327680000,
recursive = FALSE,
parallel = FALSE,
overwrite = FALSE,
call = caller_env()) {
if (dir.exists(src)) {
cli_progress_step(
msg = "Uploading directory to SharePoint drive",
Expand Down
3 changes: 3 additions & 0 deletions man/upload_sp_item.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6205f02

Please sign in to comment.