Skip to content

Commit

Permalink
add abiblity to detect citations from multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
Dewey Dunnington committed Aug 2, 2021
1 parent 9f58981 commit 5df97f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion R/detect-citations.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' [nocite front matter field](https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html#Unused_References_(nocite)).
#'
#' @param path A character vector, file or URL whose contents may contain citation keys.
#' Multiple files can be passed in as a vector (e.g., from [list.files()]).
#' @param locale See [readr::default_locale()]. Use if encoding might
#' be a problem.
#'
Expand All @@ -17,7 +18,7 @@
#' bbt_detect_citations("\n@citation1 and [@citation2] but not \\@citation3")
#'
bbt_detect_citations <- function(path = bbt_guess_citation_context(), locale = readr::default_locale()) {
text <- readr::read_file(path, locale = locale)
text <- vapply(path, readr::read_file, locale = locale, FUN.VALUE = character(1))
bbt_detect_citations_chr(text)
}

Expand Down
3 changes: 2 additions & 1 deletion man/bbt_detect_citations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-detect-citations.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ test_that("detect_citations can operate on a character vector or file", {
unlink(file)
})

test_that("detect_citations can handle a vector of files", {
f1 <- tempfile()
f2 <- tempfile()
write("\n@citation1\n", f1)
write("\n@citation2\n", f2)
expect_setequal(bbt_detect_citations(c(f1, f2)), c("citation1", "citation2"))
unlink(c(f1, f2))
})

test_that("detect_citations ignores code chunks", {
mock_content <- '
Expand Down

0 comments on commit 5df97f7

Please sign in to comment.