Skip to content

Instantly share code, notes, and snippets.

@njahn82
Last active February 8, 2018 06:48
Show Gist options
  • Select an option

  • Save njahn82/587e3df5b77bbaa17f691118293cd9b6 to your computer and use it in GitHub Desktop.

Select an option

Save njahn82/587e3df5b77bbaa17f691118293cd9b6 to your computer and use it in GitHub Desktop.
Retrieve random CC BY 4.0 articles from Elsevier as PDF
library(rcrossref)
library(purrr)
# helper function to retrieve pdfs with curl, requires api key
elsevier_fetch <- function(doi) {
u <- paste0("http://api.elsevier.com/content/article/doi/",
doi,
"?httpAccept=application%2Fpdf"
)
file_out <- URLencode(paste0(doi, ".pdf"), reserved = TRUE)
file.create(file_out)
download.file(u, destfile = file_out)
Sys.sleep(2)
}
# get 100 random works from Elsevier (Crossref member 78) with
# open license http://creativecommons.org/licenses/by/4.0/
dois <- rcrossref::cr_r(sample = 100, filter = c(member = "78",
license.url = "http://creativecommons.org/licenses/by/4.0/"))
purrr::map(dois, elsevier_fetch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment