Skip to content

Instantly share code, notes, and snippets.

@yufree
Last active January 12, 2018 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yufree/f56e693873daf926899c4f7d67d54db6 to your computer and use it in GitHub Desktop.
Save yufree/f56e693873daf926899c4f7d67d54db6 to your computer and use it in GitHub Desktop.
find doi in text and return citation
library('stringr')
library('readr')
library('rcrossref')
doiref <- function(path, style = 'apa'){
mystring <- readr::read_file(path)
doi <- unlist(stringr::str_extract_all(mystring, "\\b10\\.(\\d+\\.*)+[\\/](([^\\s\\.])+\\.*)+\\b"))
doi <- unique(doi)
ref <- vector()
for (i in 1:length(doi)){
temp <- try(rcrossref::cr_cn(dois = doi[i], format = "text", style = style), T)
ref <- c(ref,temp)
}
return(ref)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment