Skip to content

Commit

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

* inst/examples/doi2bib.r: New wrapper for DOI request for bibtex entry

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

* DESCRIPTION (Date, Version): Roll micro version and date
Expand Down
35 changes: 35 additions & 0 deletions inst/examples/doi2bib.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env r
##
## Convert a DOI to it bibtext field
##
## Copyright (C) 2024 Dirk Eddelbuettel
##
## Released under GPL (>= 2)
##
## With thanks to https://bsky.app/profile/rmcelreath.bsky.social/post/3knkqvogwbc25

## load docopt package from CRAN
library(docopt)
library(httr)

## configuration for docopt
doc <- "Usage: doi2bib.r [-h] [-x] DOI
-h --help show this help text
-x --usage show help and short example usage"

opt <- docopt(doc) # docopt parsing

if (opt$usage) {
cat(doc, "\n\n")
cat("Examples:
doi2bib..r 10.1002/evan.10110
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))

0 comments on commit b920ce1

Please sign in to comment.