Created
March 23, 2020 06:30
-
-
Save joelnitta/0f305992e09eed69e0cc5223287eb2b4 to your computer and use it in GitHub Desktop.
Make ref key list (especially for searching in Mendeley)
This file contains hidden or 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
# Extract a list of citation keys from an Rmd file, | |
# paste them together to search in Mendeley to make | |
# a list of references in that Rmd file | |
rmd_file <- "path_to_Rmd_file" | |
citations <- | |
readr::read_lines(rmd_file) %>% | |
stringr::str_split(" |;") %>% | |
unlist %>% | |
magrittr::extract(., stringr::str_detect(.,"@")) %>% | |
stringr::str_remove_all("\\[|\\]|\\)|\\(|\\.$|,|\\{|\\}") %>% | |
stringr::str_remove_all("-@") %>% | |
stringr::str_remove_all("@") %>% | |
unique %>% | |
sort | |
paste(citations, collapse = " OR ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment