R/download_abs.R

Defines functions dl_file download_abs

download_abs <- function(urls,
                         path,
                         show_progress_bars = TRUE) {

  # create a subdirectory of the working directory with value given by
  # the path argument and define the filename that will be given to the
  # downloaded table
  if (!dir.exists(path)) {
    dir.create(path = path, recursive = TRUE, showWarnings = FALSE)
  }

  filenames <- file.path(path, basename(urls))

  purrr::walk2(.x = urls,
               .y = filenames,
               .f = dl_file,
               quiet = !show_progress_bars)

  return(TRUE)
}

dl_file <- function(url, destfile, quiet = TRUE) {

  if (isFALSE(quiet)) {
    message("Downloading ", url)
  }

  utils::download.file(
    url = url,
    destfile = destfile,
    mode = "wb",
    quiet = quiet,
    headers = readabs_header,
    cacheOK = FALSE
  )
}

Try the readabs package in your browser

Any scripts or data that you put into this service are public.

readabs documentation built on Dec. 17, 2021, 1:07 a.m.