JDownload: Downloads one or more URLs and saves them to local files.

View source: R/download.R

JDownloadR Documentation

Downloads one or more URLs and saves them to local files.

Description

The intent of this function is to save time downloading files by only downloading them if they haven't previously been downloaded. Files will be downloaded if they have been modified since the previous download (as determined by HTTP If-Modified-Since header). On some platforms, caching does not seem to work correctly. On those platforms, the files are always downloaded.

Usage

JDownload(
  url,
  tempfileFn = NULL,
  cacheDir = tempdir(),
  filePattern = "jdcache",
  verbose = FALSE,
  debug = FALSE
)

Arguments

url

Character vector specifying the URLs to be downloaded.

tempfileFn

Function to create names of downloaded files. (defaults to tempfile). Must accept the same arguments as the base R function tempfile.

cacheDir

Passed to tempFileFn as the parameter tmpdir. By default, files will be created in this directory.

filePattern

Passed to tempFileFn as the parameter pattern. By default, this is used as the initial part of the file name.

verbose

If TRUE, prints status messages.

debug

If TRUE, prints debugging messages.

Details

A file is created within cacheDir which contains the URL, file name and modification date of each downloaded file in the directory. It is used to determine whether a URL needs to be downloaded again. The file is in R serialised object format (readRDS, saveRDS). The URL is always fetched (using httr::GET), however the http header If-Modified-Since is specified so that it will not be downloaded again if it is unmodified.

Value

Array of names of the downloaded files.

See Also

download.file


JimMcL/JUtils documentation built on Nov. 7, 2024, 11:25 a.m.