Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active October 23, 2022 08:42
Show Gist options
  • Save knbknb/729207b4b0eb52a417067e153f0e084b to your computer and use it in GitHub Desktop.
Save knbknb/729207b4b0eb52a417067e153f0e084b to your computer and use it in GitHub Desktop.
R: download file if not exist locally
# download remote file (potentially very big)
# only if it does not exist locally
# assumes tidyverse is already loaded
inurl <- 'https://'
infile <- 'data_infiles/.csv'
if (! file.exists(infile)){
sprintf("downloading: '%s'", inurl)
try(download.file(url = inurl, destfile = infile
#, mode = "wb",
), silent = TRUE)
} else {
sprintf("file already downloaded: '%s'", infile)
}
data_raw <- read_csv(infile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment