get_if_not_exists: Download a file if it doesn't already exist

View source: R/misc.R

get_if_not_existsR Documentation

Download a file if it doesn't already exist

Description

Download a file if it doesn't already exist

Usage

get_if_not_exists(x, destfile, read_function = readRDS, ow = FALSE, ...)

Arguments

x

url string or function to be evaluated

destfile

file.path

read_function

function to read existing files, defaults to readRDS

ow

logical force overwrite

...

parameters passed to x

Examples

## Not run: 
# unlink("data.gz")
get_if_not_exists("http://www.omegahat.net/RCurl/data.gz", "data.gz", ow = TRUE)

junk_rds <- function(destfile, add_number){
     saveRDS(1 + add_number, destfile)
     return(1 + add_number)
}
# unlink("junk.rds")
x <- get_if_not_exists(junk_rds, "junk.rds", add_number = 1)

junk_csv <- function(destfile, add_number){
     write.csv(1 + add_number, destfile, row.names = FALSE)
     return(1 + add_number)
}
# unlink("junk.csv")
x <- get_if_not_exists(junk_csv, "junk.csv", read.csv, add_number = 1)

## End(Not run)

jsta/rjsta documentation built on June 7, 2022, 8:39 p.m.