Skip to content

Commit

Permalink
change: opts_current_table() ignores quarto settings
Browse files Browse the repository at this point in the history
fix #546
  • Loading branch information
davidgohel committed Feb 3, 2024
1 parent fb92550 commit 57944a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: officer
Type: Package
Title: Manipulation of Microsoft Word and PowerPoint Documents
Version: 0.6.4.002
Version: 0.6.4.003
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"), email = "[email protected]"),
person("Stefan", "Moog", role = "aut", email = '[email protected]'),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
the id(s) of the parent paragraph(s). A possible breaking change is that the `commented_text`
is now returned as a list column to account for comments spanning multiple runs.
The docs gain a description of the columns of the returned dataframe.
- `opts_current_table()` now ignore 'Quarto' setting.

## Issues

Expand Down
40 changes: 6 additions & 34 deletions R/knitr_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,58 +177,30 @@ knitr_opts_current <- function(x, default = FALSE){
#' @keywords internal
opts_current_table <- function() {

is_quarto <- isTRUE(knitr::opts_knit$get("quarto.version") > numeric_version("0"))
is_bookdown <- isTRUE(knitr::opts_knit$get('bookdown.internal.label'))

if (is_bookdown) {
tab.lp <- knitr_opts_current("tab.lp", default = "tab:")
} else if (is_quarto) {
tab.lp <- "tab:"
} else {
tab.lp <- knitr_opts_current("tab.lp", default = NULL)
}
if (is_quarto) {
tab.topcaption <- knitr_opts_current("tbl-cap-location", default = "top") %in% "top"
} else {
tab.topcaption <- knitr_opts_current("tab.topcaption", default = TRUE)
}
tab.topcaption <- knitr_opts_current("tab.topcaption", default = TRUE)

tab.cap.pre <- knitr_opts_current("tab.cap.pre", default = "Table")
tab.cap.sep <- knitr_opts_current("tab.cap.sep", default = ":")

if (is_quarto) {
tab.cap.pre <- knitr_opts_current("tbl-title", default = "Table")
tab.cap.sep <- knitr_opts_current("title-delim", default = ":")
} else {
tab.cap.pre <- knitr_opts_current("tab.cap.pre", default = "Table")
tab.cap.sep <- knitr_opts_current("tab.cap.sep", default = ":")
}
tab.cap.pre <- paste0(tab.cap.pre, " ")
tab.cap.sep <- paste0(tab.cap.sep, " ")

if (is_quarto) {
tab.cap <- knitr_opts_current("tbl-cap", default = NULL)
} else {
tab.cap <- knitr_opts_current("tab.cap", default = NULL)
}
tab.cap <- knitr_opts_current("tab.cap", default = NULL)

if (is_quarto) {
tab.id <- knitr_opts_current("label", default = NULL)
if(!is.null(tab.id)) {
if (grepl("^unnamed\\-chunk", tab.id)) {
tab.id <- NULL
}
}
} else if (is_bookdown) {
if (is_bookdown) {
tab.id <- knitr_opts_current("label", default = NULL)
tab.id <- knitr_opts_current("tab.id", default = tab.id)
} else {
tab.id <- knitr_opts_current("tab.id", default = NULL)
}

if (is_quarto) {
if(is.null(tab.cap) && !is.null(tab.id)) {
stop("if a label (", tab.id, ") is defined, chunk option `tbl-cap` should also be defined.")
}
}

tab.cap.style <- knitr_opts_current("tab.cap.style", default = NULL)
tab.alt.title <- knitr_opts_current("tab.alt.title", default = NULL)
tab.alt.description <- knitr_opts_current("tab.alt.description", default = NULL)
Expand Down

0 comments on commit 57944a7

Please sign in to comment.