R/upload.R

Defines functions duck_upload

Documented in duck_upload

#' Upload Files
#'
#' Upload (new) files to a remote location.
#'
#' @param path Path of local file.
#' @param url The duck URL for a remote file.
#' @param exist What to do when remote exists. Defaults to skip.
#' @param user The username or access key. Define with [duck_user()].
#' @param ... Additional arguments passed to duck.
#' @return The URL to the uploaded files (invisibly).
#' @examples
#' duck_upload(tempfile(), "s3:/publicaccountability/csv/vt_voters.csv")
#' @importFrom fs as_fs_path
#' @export
duck_upload <- function(path, url, exist = "skip", user = Sys.getenv("S3_USER"), ...) {
  dots <- list(...)
  arg_down <- paste("--upload", url, path)
  arg_user <- paste("--user", user)
  match.arg(exist, c("append", "overwrite", "rename", "skip", "cancel"))
  arg_exist <- paste("--existing", exist)
  system2(
    command = "duck",
    args = c("--quiet", arg_down, arg_user, arg_exist, dots),
    stdout = TRUE,
    stderr = "",
  )
  invisible(fs::as_fs_path(url))
}
kiernann/duckr documentation built on May 12, 2020, 11:19 p.m.