Last active
January 18, 2023 10:29
-
-
Save StefanThoma/6e8db5f46ca586922b22e702f3cb97f7 to your computer and use it in GitHub Desktop.
download (example) data from github
This file contains 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
# set paths and data names | |
external.path <- | |
"https://github.com/pharmaverse/intro-to-r-for-sas-programmers-workshop/blob/main/data" | |
# should we check first? | |
check <- TRUE | |
local.path <- ("data") | |
subdir <- file.path(local.path, "save_data") | |
files <- c( | |
"adsl.RData", | |
"adsl.csv", | |
"adsl.sas7bdat", | |
"adsl_1.RData", | |
"adsl_2.RData", | |
"ae.rds", | |
"dm.rds", | |
"ds.rds", | |
"ex.rds", | |
"suppdm.rds", | |
"suppds.rds" | |
) | |
# external files (with path) | |
urls <- file.path(external.path, paste(files, "raw=true", sep = "?")) | |
# local files (with path) | |
dest <- file.path(local.path, files) | |
# create data folder in wd | |
if (!file.exists(local.path)) { | |
dir.create(local.path) | |
# subdirectory | |
dir.create(subdir) | |
} | |
# download files | |
## if needed | |
if(check){ | |
needed <- !files %in% list.files(local.path) | |
# only if any files need to be downloaded, we download: | |
if(sum(needed)>0){ | |
download.file(urls[needed], destfile = dest[needed]) | |
} | |
} else { | |
download.file(urls, destfile = dest) | |
} | |
# delete all files | |
# unlink(dest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment