Skip to content

Commit

Permalink
Enhancements to doi2bib.r
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Mar 14, 2024
1 parent b920ce1 commit 5b821a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-03-14 Dirk Eddelbuettel <edd@debian.org>

* inst/examples/doi2bib.r: Allow multiple DOIs, check packages

2024-03-13 Dirk Eddelbuettel <edd@debian.org>

* inst/examples/doi2bib.r: New wrapper for DOI request for bibtex entry
Expand Down
16 changes: 11 additions & 5 deletions inst/examples/doi2bib.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

## load docopt package from CRAN
library(docopt)

if (!requireNamespace("httr", quietly=TRUE))
stop("Please install 'httr' from CRAN.", call. = FALSE)

library(httr)

## configuration for docopt
doc <- "Usage: doi2bib.r [-h] [-x] DOI
doc <- "Usage: doi2bib.r [-h] [-x] DOI...
-h --help show this help text
-x --usage show help and short example usage"
Expand All @@ -23,13 +27,15 @@ opt <- docopt(doc) # docopt parsing
if (opt$usage) {
cat(doc, "\n\n")
cat("Examples:
doi2bib..r 10.1002/evan.10110
doi2bib.r 10.1002/evan.10110 10.1007/978-1-4614-6868-4
doi2bib.r is part of littler which brings 'r' to the command-line.
See http://dirk.eddelbuettel.com/code/littler.html for more information.\n")
q("no")
}

res <- GET(paste0("https://doi.org/", opt$DOI),
add_headers(Accept="application/x-bibtex"))
cat(rawToChar(res$content))
for (arg in opt$DOI) {
res <- GET(paste0("https://doi.org/", arg),
add_headers(Accept="application/x-bibtex"))
cat(rawToChar(res$content))
}

0 comments on commit 5b821a9

Please sign in to comment.