Last active
February 8, 2018 06:48
-
-
Save njahn82/587e3df5b77bbaa17f691118293cd9b6 to your computer and use it in GitHub Desktop.
Retrieve random CC BY 4.0 articles from Elsevier as PDF
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
| 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