Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option of multiple messy bib files #80

Merged
merged 3 commits into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 path or a vector of 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 vector 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