Skip to content

Commit

Permalink
Added option of multiple messy bib files
Browse files Browse the repository at this point in the history
Line 6: changed description messy_bibliography parameter
Line 23: changed to allow for messy_bibliography to be a list of characters
Line 54-57: changed to allow for multiple messy bib files to be used as input in the function tidy_bib_file(), similar to how multiple Rmd files are possible as input.
  • Loading branch information
ilsePit authored Dec 30, 2020
1 parent c4ad052 commit d79b4f9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions R/tidy_bib_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Removes duplicate and unneeded entries from a Bib(La)Tex-file.
#'
#' @param rmd_file Character. One or more paths to the R Markdown files that use the messy bibliography file.
#' @param messy_bibliography Character. Path to the messy bibliography file.
#' @param messy_bibliography Character. One path or a list of paths to the messy bibliography file(s).
#' @param file Character. Path and name for the to-be-created tidy bibliography. If \code{NULL} the messy bibliography is replaced.
#' @inheritParams query_bib
#'
Expand All @@ -20,7 +20,7 @@ tidy_bib_file <- function(
, betterbiblatex_format = getOption("citr.betterbiblatex_format")
) {
assert_that(is.character(rmd_file))
assert_that(is.string(messy_bibliography))
assert_that(is.character(messy_bibliography))
if(!is.null(file)) {
assert_that(is.string(file))
} else {
Expand Down Expand Up @@ -51,8 +51,11 @@ tidy_bib_file <- function(

if(length(reference_handles) == 0) stop("Found no references in ", rmd_file)

complete_bibliography <- RefManageR::ReadBib(messy_bibliography, check = FALSE, .Encoding = encoding)

complete_bibliography <- c()
for(i in seq_along(messy_bibliography)) {
complete_bibliography <- append(complete_bibliography, RefManageR::ReadBib(messy_bibliography[i], check = FALSE, .Encoding = encoding))
}

necessary_bibliography <- complete_bibliography[names(complete_bibliography) %in% reference_handles]

if(length(necessary_bibliography) == 0) stop("Found none of the ", length(reference_handles), " necessary references in the look-up bibliography.")
Expand Down

0 comments on commit d79b4f9

Please sign in to comment.