Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Created March 23, 2020 06:30
Show Gist options
  • Save joelnitta/0f305992e09eed69e0cc5223287eb2b4 to your computer and use it in GitHub Desktop.
Save joelnitta/0f305992e09eed69e0cc5223287eb2b4 to your computer and use it in GitHub Desktop.
Make ref key list (especially for searching in Mendeley)
# 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