Skip to content

Instantly share code, notes, and snippets.

@larsvilhuber
Created March 5, 2024 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsvilhuber/6b5048a22904cffd59583db95f9f0542 to your computer and use it in GitHub Desktop.
Save larsvilhuber/6b5048a22904cffd59583db95f9f0542 to your computer and use it in GitHub Desktop.
Downloading from Zenodo (2024)
# 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