Last active
October 23, 2022 08:42
-
-
Save knbknb/729207b4b0eb52a417067e153f0e084b to your computer and use it in GitHub Desktop.
R: download file if not exist locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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