Last active
January 12, 2018 02:34
-
-
Save yufree/f56e693873daf926899c4f7d67d54db6 to your computer and use it in GitHub Desktop.
find doi in text and return citation
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
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