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