Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Authors@R: c(
)
Imports: bookdown, knitr (>= 1.30), rmarkdown (>= 1.2), stats, utils, yaml,
BiocManager
Suggests: BiocGenerics, RUnit, htmltools
Suggests: BiocGenerics, RUnit, htmltools, quarto
biocViews: Software
License: Artistic-2.0
VignetteBuilder: knitr
SystemRequirements: quarto
Encoding: UTF-8
URL: https://github.com/Bioconductor/BiocStyle
BugReports: https://github.com/Bioconductor/BiocStyle/issues
RoxygenNote: 6.1.0
Date: 2025-08-01
RoxygenNote: 7.3.2
139 changes: 139 additions & 0 deletions R/utils-vignettes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
## BiocStyle vignette engine registration
## Adapted from github.com/quarto-dev/quarto-r/blob/main/R/utils-vignettes.R
register_vignette_engines <- function(pkg) {
vig_engine("html", quarto_format = "html")
}

vig_engine <- function(..., quarto_format) {
rmd_eng <- tools::vignetteEngine("rmarkdown", package = "knitr")
tools::vignetteEngine(
...,
weave = vweave_quarto(quarto_format),
tangle = rmd_eng$tangle,
pattern = "[.]qmd$",
package = "BiocStyle",
aspell = rmd_eng$aspell
)
}

vweave_quarto <- function(format) {
meta <- get_meta(format)
function(file, driver, syntax, encoding, quiet = FALSE, ...) {
# protect if Quarto is not installed
if (is.null(quarto::quarto_path())) {
msg <- c(
paste(
"Quarto binary is required to build Quarto vignettes",
"but is not available.",
),
i = paste(
"Please make sure it is installed and found",
"by {.code find_quarto()}."
)
)
if (is_R_CMD_check()) {
cli::cli_inform(msg)
} else {
cli::cli_abort(msg, call = NULL)
}
return(vweave_empty(file))
}

# Log debug information using the new configurable logging function
quarto:::quarto_log("R_LIBS: ", Sys.getenv("R_LIBS"))
quarto:::quarto_log(
".libPaths(): ",
paste0(.libPaths(), collapse = ":")
)
quarto:::quarto_log(
"Packages: ",
paste0(dir(.libPaths()[1]), collapse = ",")
)

quarto::quarto_render(
file,
...,
output_format = format,
metadata = meta
)
}
}

get_meta <- function(format) {
if (is.null(format)) {
return(NULL)
}
if (format == "html") {
return(get_meta_for_html())
}
if (format == "pdf") {
return(get_meta_for_pdf())
}
}

get_meta_for_pdf <- function() {
meta <- list()
meta$format$pdf <- list(
# don't try to install CTAN package on CRAN environment
`latex-auto-install` = !is_cran_check()
)
meta
}

get_meta_for_html <- function() {
css <- system.file(
"resources",
"html",
"biocstyle.css",
package = "BiocStyle"
)
scss <- system.file(
"resources",
"html",
"biocstyle.scss",
package = "BiocStyle"
)
meta <- list()
meta$format$html <-
list(
`embed-resources` = TRUE,
minimal = TRUE,
toc = TRUE,
`toc-float` = TRUE,
`toc-depth` = 3L,
`toc-location` = "left",
`number-sections` = TRUE,
theme = scss,
css = css
)
meta
}

is_R_CMD_check <- function() {
!is.na(Sys.getenv("_R_CHECK_PACKAGE_NAME_", NA)) ||
tolower(Sys.getenv("_R_CHECK_LICENSE_")) == "true"
}

# from knitr internal
is_cran_check <- function() {
is_cran() && is_R_CMD_check()
}

is_cran <- function() {
!rlang::is_interactive() &&
!isTRUE(as.logical(Sys.getenv("NOT_CRAN", "false")))
}

# trick from knitr to avoid problem on R CMD check (e.g. when no Quarto
# available) It will silently skip the vignette
vweave_empty <- function(file, ..., .reason = "Quarto") {
out <- sprintf("%s.html", tools::file_path_sans_ext(basename(file)))
writeLines(
sprintf(
"The vignette could not be built because %s is not available.",
.reason
),
out
)
out
}
3 changes: 2 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
resources <- bioconductor.sty <- bioconductor.css <- NULL

# resolve paths once during package load
.onLoad <- function(...) {
.onLoad <- function(lib, pkg) {
register_vignette_engines(pkg)
resources <<- system.file(package = "BiocStyle", "resources")
bioconductor.sty <<- file.path(resources, "tex", "Bioconductor.sty")
bioconductor.css <<- file.path(resources, "html", "bioconductor.css")
Expand Down
Loading