Skip to content

Instantly share code, notes, and snippets.

@jsta
Last active March 3, 2017 22:48
Show Gist options
  • Save jsta/fe3da0dde410eb162cc974282b0d53a5 to your computer and use it in GitHub Desktop.
Save jsta/fe3da0dde410eb162cc974282b0d53a5 to your computer and use it in GitHub Desktop.
Extract doi from bibtex R
dt <- knitcitations::read.bibtex("foo.bib")
dt <- dt[grep("doi", tolower(dt)),]
res <- stringr::str_extract(dt, "(?=10)(.*?)(?<=\\s)")
res <- as.character(sapply(res, function(x) substring(x, 1, nchar(x) - 3)))
(res <- res[!is.na(res)])
# paste0("http://dx.doi.org/", res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment