-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
383e1df
commit b920ce1
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
2024-03-13 Dirk Eddelbuettel <[email protected]> | ||
|
||
* inst/examples/doi2bib.r: New wrapper for DOI request for bibtex entry | ||
|
||
2024-03-11 Dirk Eddelbuettel <[email protected]> | ||
|
||
* DESCRIPTION (Date, Version): Roll micro version and date | ||
|
This file contains 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
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)) |