Skip to content

Commit

Permalink
Adds betterbiblatex_format option to tidy_bib_file(). Resolves #61
Browse files Browse the repository at this point in the history
  • Loading branch information
crsh committed Feb 11, 2020
1 parent 0a56c35 commit 0afd6f9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ Suggests:
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: TRUE
RoxygenNote: 6.1.0
RoxygenNote: 7.0.2
12 changes: 6 additions & 6 deletions R/query_bib.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' Requires that the \href{https://github.com/retorquere/zotero-better-bibtex}{Better BibTeX} is installed and
#' Zotero/Juris-M is running.
#' @param exclude_betterbiblatex_library Character. A vector of Zotero/Juris-M library names not to query.
#' @param encoding Character. Encoding of the Bib(La)TeX-file.
#' @param encoding Character. Encoding of the Bib(La)TeX-file. See the \code{\link{connection}}.
#'
#' @details The path to the BibTeX-file can be set in the global options and is set to
#' \code{references.bib} when the package is loaded. Once the path is changed in the
Expand Down Expand Up @@ -154,19 +154,19 @@ betterbiblatex_available <- function() {

#' Load bibliography from Zotero
#'
#' @param increment_progress logical switch which will use the shiny function \code{incProgress} when \code{TRUE}.
#' \code{FALSE} by default.
#' @inheritParams query_bib
#' @inheritParams tidy_bib_file
#' @param increment_progress logical switch which will use the shiny function
#' \code{incProgress} when \code{TRUE}. \code{FALSE} by default.
#' @inheritParams query_bib
#'
#' This function loads into RAM the bibliography stored in Zotero.
#' @details This function loads into RAM the bibliography stored in Zotero.
#' May take a several seconds if you have many hundreds of references.
#'
#' @export
#'
#' @examples \dontrun{
#' b <- load_betterbiblatex_bib(encoding = "UTF-8")
#' }

load_betterbiblatex_bib <- function(
encoding
, betterbiblatex_format = "bibtex"
Expand Down
9 changes: 7 additions & 2 deletions R/tidy_bib_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @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 file Character. Path and name for the to-be-created tidy bibliography. If \code{NULL} the messy bibliography is replaced.
#' @param encoding Character. The name of the encoding to be assumed. See the \code{\link{connection}}.
#' @inheritParams query_bib
#'
#' @export
#'
Expand All @@ -17,6 +17,7 @@ tidy_bib_file <- function(
, messy_bibliography
, file = NULL
, encoding = getOption("citr.encoding")
, betterbiblatex_format = getOption("citr.betterbiblatex_format")
) {
assert_that(is.character(rmd_file))
assert_that(is.string(messy_bibliography))
Expand All @@ -27,6 +28,10 @@ tidy_bib_file <- function(
}
assert_that(is.string(encoding))
assert_that(length(encoding) == 1)
assert_that(is.string(betterbiblatex_format))
if(!betterbiblatex_format %in% c("bibtex", "biblatex")) {
stop("Bibliography format not supported. Use either 'bibtex' or 'biblatex'.")
}

rmd <- c()
for(i in seq_along(rmd_file)) {
Expand Down Expand Up @@ -59,7 +64,7 @@ tidy_bib_file <- function(
bib_options <- RefManageR::BibOptions()
RefManageR::BibOptions(check.entries = FALSE)

RefManageR::WriteBib(unique(necessary_bibliography), file = file, useBytes = TRUE, biblatex = getOption("citr.betterbiblatex_format") == "biblatex")
RefManageR::WriteBib(unique(necessary_bibliography), file = file, useBytes = TRUE, biblatex = betterbiblatex_format == "biblatex")

RefManageR::BibOptions(bib_options)
}
Expand Down
8 changes: 5 additions & 3 deletions man/insert_citation.Rd

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

18 changes: 13 additions & 5 deletions man/load_betterbiblatex_bib.Rd

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

12 changes: 8 additions & 4 deletions man/md_cite.Rd

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

9 changes: 6 additions & 3 deletions man/query_bib.Rd

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

15 changes: 12 additions & 3 deletions man/tidy_bib_file.Rd

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

0 comments on commit 0afd6f9

Please sign in to comment.