Skip to content

Instantly share code, notes, and snippets.

@wkmor1
Created March 15, 2016 00:39
Show Gist options
  • Save wkmor1/ae2cc96acad472d49c35 to your computer and use it in GitHub Desktop.
Save wkmor1/ae2cc96acad472d49c35 to your computer and use it in GitHub Desktop.
#' Convert doi to bibtex
#'
#' Convert a digital object identifier (doi) string into a bibtex entry using the
#' webserice \link{http://www.doi2bib.org}.
#'
#' @param doi The character string of the doi.
#'
#' @return a bibtex entry as a character string.
#'
#' @importFrom httr accept content GET
#'
#' @example
#' doi2bib("10.1038/350132215)
#'
#' @export
setGeneric(
"doi2bib",
function(doi) {
standardGeneric("doi2bib")
}
)
setMethod(
"doi2bib",
c(doi = "character"),
function (doi) {
content(
GET(
url = "http://www.doi2bib.org/",
config = accept("application/x-bibtex"),
path = "doi2bib",
query = list(id = doi)
),
as = "text"
)
}
)
@adamhsparks
Copy link

Thanks for sharing this, just a couple corrections.

Line 12 should be @examples
Line 13 is missing a " to close the string

@adamhsparks
Copy link

Ah, found your package. Google found this first, I'll leave this link here for others that might stumble here first like I did:
https://github.com/wkmor1/doi2bib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment