R/download.R

Defines functions duck_download

Documented in duck_download

#' Download Files
#'
#' Download files from a remote location.
#'
#' @param url The duck URL for a remote file.
#' @param path Path to write to.
#' @param user The username or access key. Define with [duck_user()].
#' @param ... Additional arguments passed to duck.
#' @return The path to the downloaded files (invisibly).
#' @examples
#' duck_download("s3:/publicaccountability/csv/vt_voters.csv", tempfile())
#' @importFrom fs as_fs_path
#' @export
duck_download <- function(url, path, user = Sys.getenv("S3_USER"), ...) {
  dots <- list(...)
  arg_down <- paste("--download", url, path)
  arg_user <- paste("--user", user)
  system2(
    command = "duck",
    args = c("--quiet", arg_down, arg_user, dots),
    stdout = TRUE,
    stderr = "",
  )
  invisible(fs::as_fs_path(path))
}
kiernann/duckr documentation built on May 12, 2020, 11:19 p.m.