Skip to content

Instantly share code, notes, and snippets.

@johnbaums
Last active January 24, 2020 04:48
Show Gist options
  • Save johnbaums/c92081ebaca913cf5c5c58892809144f to your computer and use it in GitHub Desktop.
Save johnbaums/c92081ebaca913cf5c5c58892809144f to your computer and use it in GitHub Desktop.
Return a bib file for a vector of DOIs
doi2bib <- function(dois, file=NULL, quiet=FALSE) {
# dois: vector of dois
require(httr)
bibs <- sapply(dois, function(x) {
if(!quiet) message(x)
response <- httr::GET(
'http://dx.doi.org', path=x,
add_headers(Accept = 'application/x-bibtex')
)
httr::content(response, as='text', encoding='UTF-8')
})
if(!is.null(file)) {
cat(bibs, file=file, sep='\n\n')
}
bibs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment