Download file if does not exist yet.
Usage
download_file(
url,
dir = tempdir(),
fname = url_basename(url),
overwrite = FALSE,
mode = "wb",
...
)
Arguments
- url
URL of file to be downloaded.
- dir
Directory where to download the file.
- fname
Base name of the downloaded file (
dir
will be prefixed).- overwrite
Whether to overwrite? Default is
FALSE
.- mode
See parameter of
download.file()
. Default of "wb" seems useful for Windows systems.- ...
Arguments passed on to
utils::download.file
method
Method to be used for downloading files. Current download methods are
"internal"
,"wininet"
(Windows only)"libcurl"
,"wget"
and"curl"
, and there is a value"auto"
: see ‘Details’ and ‘Note’.The method can also be set through the option
"download.file.method"
: seeoptions()
.quiet
If
TRUE
, suppress status messages (if any), and the progress bar.cacheOK
logical. Is a server-side cached value acceptable?
extra
character vector of additional command-line arguments for the
"wget"
and"curl"
methods.headers
named character vector of HTTP headers to use in HTTP requests. It is ignored for non-HTTP URLs. The
User-Agent
header, coming from theHTTPUserAgent
option (seeoptions
) is used as the first header, automatically.
Examples
download_file("https://github.com/privefl.png")
#> [1] "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmpeczrs1/privefl.png"
download_file("https://github.com/privefl.png")
#> [1] "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmpeczrs1/privefl.png"
download_file("https://github.com/privefl.png", overwrite = TRUE)
#> [1] "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmpeczrs1/privefl.png"