cachaca: best file download, all other file downloads have inferior...

cachacaR Documentation

best file download, all other file downloads have inferior potassium

Description

check remote file size. check cache for a match and if it exists, copy it over. otherwise, download the file, confirm file size, save to cache too

Usage

cachaca(this_url, destfile = NULL, ..., FUN = download.file, attempts = 3,
  sleepsec = 60, filesize_fun = "httr",
  savecache = getOption("lodown.cachaca.savecache", TRUE),
  cdc_ftp_https = TRUE)

Arguments

this_url

where to download from

destfile

where to save locally, unnecessary when returning an object with httr::GET or RCurl::getBinaryURL

...

passed to FUN

FUN

defaults to download.file but downloader::download, httr::GET, RCurl::getBinaryURL also work

attempts

number of times to retry a broken download

sleepsec

length of Sys.sleep() between broken downloads

filesize_fun

use httr::HEAD or RCurl::getURL to determine file size. use "unzip_verify" to verify the download by attempting to unzip the file without issue

savecache

whether to actually cache the downloaded files in the temporary directories. setting this option to FALSE eliminates the purpose of cachaca(), but sometimes it's necessary to disable for a single call, or globally.

cdc_ftp_https

whether to substitute cdc ftp sites with https, i.e. gsub( "ftp://ftp.cdc.gov/" , "https://ftp.cdc.gov/" , this_url , fixed = TRUE ).

Value

just pass on whatever FUN returns

Examples


## Not run: 

# only the first of these two lines downloads the file.  the second line uses the cached file
tf <- tempfile()
cachaca( "https://www.r-project.org/logo/Rlogo.png" , tf , mode = 'wb' )
cachaca( "https://www.r-project.org/logo/Rlogo.png" , tf , mode = 'wb' )

# option to disable cache in case the files are too big
options( "lodown.cachaca.savecache" = FALSE )
cachaca( "https://www.r-project.org/logo/Rlogo.svg" , tf , mode = 'wb' )
cachaca( "https://www.r-project.org/logo/Rlogo.svg" , tf , mode = 'wb' )


## End(Not run)


ajdamico/lodown documentation built on Oct. 21, 2024, 4:53 p.m.