Created
March 5, 2024 17:58
-
-
Save larsvilhuber/6b5048a22904cffd59583db95f9f0542 to your computer and use it in GitHub Desktop.
Downloading from Zenodo (2024)
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
# this has worked as of 2024-03-01 | |
# Specific DOI - resolves to a fixed version | |
zenodo.id <- "123456" | |
# We will recover the rest from Zenodo API | |
zenodo.api = "https://zenodo.org/api/records/" | |
# where to save | |
dataloc <- here::here("data","downloaded | |
download.file(paste0(zenodo.api,zenodo.id),destfile=file.path(dataloc,"metadata.json")) | |
latest <- fromJSON(file=file.path(dataloc,"metadata.json")) | |
print(paste0("DOI: ",latest$links$doi)) | |
print(paste0("Current: ",latest$links$html)) | |
print(paste0("Latest: ",latest$links$latest_html)) | |
# we download all the Rds files | |
file.list <- as.data.frame(latest$files) %>% select(starts_with("self")) %>% gather() | |
for ( value in file.list$value ) { | |
print(value) | |
if ( grepl("Rds",value ) ) { | |
file.name <- basename(value %>% str_remove("/content")) | |
message(paste0("Downloading... ",file.name)) | |
download.file(value,destfile=file.path(dataloc,file.name)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment