From a1dbd20fdf503ffd6e0475b62c5e7db7842b2671 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 16:52:28 +0100 Subject: [PATCH 01/30] Correctly handle null value And mock function to test no quarto installed --- DESCRIPTION | 2 +- R/quarto.R | 4 +++- tests/testthat/_snaps/quarto.md | 9 +++++++++ tests/testthat/test-quarto.R | 8 ++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 94f4f8e..8d1aee1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ Suggests: curl, knitr, rsconnect (>= 0.8.26), - testthat (>= 3.1.0), + testthat (>= 3.1.7), withr, xfun VignetteBuilder: diff --git a/R/quarto.R b/R/quarto.R index b2c59d4..e4ea6b7 100644 --- a/R/quarto.R +++ b/R/quarto.R @@ -124,7 +124,7 @@ check_quarto_version <- function(ver, what, url) { #' @export quarto_binary_sitrep <- function(verbose = TRUE, debug = FALSE) { - quarto_found <- normalizePath(quarto_path(), mustWork = FALSE) + quarto_found <- quarto_path() if (is.null(quarto_found)) { if (verbose) { cli::cli_alert_danger(quarto_not_found_msg) @@ -132,6 +132,8 @@ quarto_binary_sitrep <- function(verbose = TRUE, debug = FALSE) { return(FALSE) } + quarto_found <- normalizePath(quarto_found, mustWork = FALSE) + same_config <- TRUE if (debug) verbose <- TRUE diff --git a/tests/testthat/_snaps/quarto.md b/tests/testthat/_snaps/quarto.md index 8d3700f..bda9621 100644 --- a/tests/testthat/_snaps/quarto.md +++ b/tests/testthat/_snaps/quarto.md @@ -77,3 +77,12 @@ Output [1] TRUE +--- + + Code + quarto_binary_sitrep(debug = TRUE) + Message + x Quarto command-line tools path not found! Please make sure you have installed and added Quarto to your PATH or set the QUARTO_PATH environment variable. + Output + [1] FALSE + diff --git a/tests/testthat/test-quarto.R b/tests/testthat/test-quarto.R index acbe22a..81b68c6 100644 --- a/tests/testthat/test-quarto.R +++ b/tests/testthat/test-quarto.R @@ -65,4 +65,12 @@ test_that("quarto CLI sitrep", { transform = transform_quarto_cli_in_output(full_path = TRUE, normalize_path = TRUE) ) ) + + # Mock no quarto found + with_mocked_bindings( + quarto_path = function(...) NULL, + expect_snapshot( + quarto_binary_sitrep(debug = TRUE) + ) + ) }) From 17ae1386529adcac0c058cff87005bf0c0dc7859 Mon Sep 17 00:00:00 2001 From: "David C. Norris" Date: Fri, 3 Nov 2023 06:58:57 -0400 Subject: [PATCH 02/30] Vignette engines for Quarto (#57) --- DESCRIPTION | 3 ++- NAMESPACE | 1 + R/zzz.R | 24 ++++++++++++++++++++++++ vignettes/hello.qmd | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 R/zzz.R create mode 100644 vignettes/hello.qmd diff --git a/DESCRIPTION b/DESCRIPTION index 8d1aee1..6d35140 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,7 @@ Imports: rmarkdown, rstudioapi, utils, + tools, yaml Suggests: curl, @@ -31,7 +32,7 @@ Suggests: withr, xfun VignetteBuilder: - knitr + knitr, quarto Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 1c1fcb6..9e9fa9f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,5 +26,6 @@ importFrom(rlang,is_interactive) importFrom(rmarkdown,relative_to) importFrom(rstudioapi,isAvailable) importFrom(rstudioapi,viewer) +importFrom(tools,vignetteEngine) importFrom(utils,browseURL) importFrom(yaml,write_yaml) diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..ea3fc46 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,24 @@ + +#' Register engines to support Quarto vignettes +#' @importFrom tools vignetteEngine +#' @noRd +.onLoad <- function(libname, pkgname) { # args ignored + vignetteEngine(name = "pdf", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "pdf") + }, + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell + ) + vignetteEngine(name = "html", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "html") + }, + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell + ) +} diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd new file mode 100644 index 0000000..bd4a093 --- /dev/null +++ b/vignettes/hello.qmd @@ -0,0 +1,36 @@ +--- +title: "Quarto Vignettes" +format: + pdf: + toc: false + html: + toc: true +vignette: > + %\VignetteIndexEntry{Vignettes} + %\VignetteEngine{quarto::pdf} + %\VignetteEncoding{UTF-8} +--- + +## Hello Vignette World! + +This is an example Quarto vignette, demonstrating how the **quarto** package can let you write package vignettes in Quarto. + +## Two Vignette Engines + +The **quarto** package registers 2 vignette engines, `quarto::pdf` and `quarto::html`. Either of these may be selected in a Quarto vignette's YAML header. For example, this vignette's header reads: +```yaml +--- +title: "Quarto Vignettes" +format: + pdf: + toc: false + html: + toc: true +vignette: > + %\VignetteIndexEntry{Vignettes} + %\VignetteEngine{quarto::pdf} + %\VignetteEncoding{UTF-8} +--- +``` + +Consequently, a PDF version of this vignette is built. From 2ff3300912f56d9b12b5a3db78a0ad1df104afa8 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 3 Nov 2023 12:03:27 +0100 Subject: [PATCH 03/30] Refactor a little --- DESCRIPTION | 5 +++-- R/quarto-package.R | 1 + R/utils-vignettes.R | 22 ++++++++++++++++++++++ R/zzz.R | 26 +++----------------------- 4 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 R/utils-vignettes.R diff --git a/DESCRIPTION b/DESCRIPTION index 6d35140..ee78b25 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,8 +21,8 @@ Imports: rlang, rmarkdown, rstudioapi, - utils, tools, + utils, yaml Suggests: curl, @@ -32,7 +32,8 @@ Suggests: withr, xfun VignetteBuilder: - knitr, quarto + knitr, + quarto Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/R/quarto-package.R b/R/quarto-package.R index 661d072..01c3ea2 100644 --- a/R/quarto-package.R +++ b/R/quarto-package.R @@ -4,5 +4,6 @@ ## usethis namespace: start #' @import rlang #' @importFrom cli cli_inform +#' @importFrom tools vignetteEngine ## usethis namespace: end NULL diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R new file mode 100644 index 0000000..2949acf --- /dev/null +++ b/R/utils-vignettes.R @@ -0,0 +1,22 @@ +register_vignette_engines <- function(pkg) { + vignetteEngine( + name = "pdf", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "pdf") + }, + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell + ) + vignetteEngine( + name = "html", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "html") + }, + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell + ) +} diff --git a/R/zzz.R b/R/zzz.R index ea3fc46..6ef8350 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,24 +1,4 @@ - -#' Register engines to support Quarto vignettes -#' @importFrom tools vignetteEngine -#' @noRd -.onLoad <- function(libname, pkgname) { # args ignored - vignetteEngine(name = "pdf", - package = "quarto", - pattern = "[.]qmd$", - weave = function(file, ..., encoding = "UTF-8") { - quarto_render(file, ..., output_format = "pdf") - }, - tangle = vignetteEngine("knitr::rmarkdown")$tangle, - aspell = vignetteEngine("knitr::rmarkdown")$aspell - ) - vignetteEngine(name = "html", - package = "quarto", - pattern = "[.]qmd$", - weave = function(file, ..., encoding = "UTF-8") { - quarto_render(file, ..., output_format = "html") - }, - tangle = vignetteEngine("knitr::rmarkdown")$tangle, - aspell = vignetteEngine("knitr::rmarkdown")$aspell - ) +# Register engines to support Quarto vignettes +.onLoad <- function(lib, pkg) { + register_vignette_engines(pkg) } From 0498b130ccc8261c19eb4766177358840c185a81 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 3 Nov 2023 15:28:51 +0100 Subject: [PATCH 04/30] Refactor the vignette engine code --- R/utils-vignettes.R | 35 ++++++++++---------- vignettes/{publishing.Rmd => publishing.qmd} | 6 ++-- 2 files changed, 22 insertions(+), 19 deletions(-) rename vignettes/{publishing.Rmd => publishing.qmd} (98%) diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index 2949acf..9bc1435 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -1,22 +1,23 @@ register_vignette_engines <- function(pkg) { - vignetteEngine( - name = "pdf", - package = "quarto", + vig_engine("html", quarto_format = "html") + vig_engine("pdf", quarto_format = "pdf") +} + + +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$", - weave = function(file, ..., encoding = "UTF-8") { - quarto_render(file, ..., output_format = "pdf") - }, - tangle = vignetteEngine("knitr::rmarkdown")$tangle, - aspell = vignetteEngine("knitr::rmarkdown")$aspell - ) - vignetteEngine( - name = "html", package = "quarto", - pattern = "[.]qmd$", - weave = function(file, ..., encoding = "UTF-8") { - quarto_render(file, ..., output_format = "html") - }, - tangle = vignetteEngine("knitr::rmarkdown")$tangle, - aspell = vignetteEngine("knitr::rmarkdown")$aspell + aspell = rmd_eng$aspell ) } + +vweave_quarto <- function(format) { + function(file, driver, syntax, encoding, quiet = FALSE, ...) { + quarto_render(file, ..., output_format = format) + } +} diff --git a/vignettes/publishing.Rmd b/vignettes/publishing.qmd similarity index 98% rename from vignettes/publishing.Rmd rename to vignettes/publishing.qmd index f9e945d..ca9d0d6 100644 --- a/vignettes/publishing.Rmd +++ b/vignettes/publishing.qmd @@ -1,9 +1,11 @@ --- title: "Publishing" -output: rmarkdown::html_vignette +format: + html: + minimal: false vignette: > %\VignetteIndexEntry{Publishing} - %\VignetteEngine{knitr::rmarkdown} + %\VignetteEngine{quarto::html} %\VignetteEncoding{UTF-8} --- From d89a064673463d2429e119971a07e884b872d9a9 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 3 Nov 2023 15:29:39 +0100 Subject: [PATCH 05/30] embed the resource for HTML vignettes --- R/utils-vignettes.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index 9bc1435..45b65c3 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -17,7 +17,9 @@ vig_engine <- function(..., quarto_format) { } vweave_quarto <- function(format) { + meta <- list() + meta["embed-resources"] <- TRUE function(file, driver, syntax, encoding, quiet = FALSE, ...) { - quarto_render(file, ..., output_format = format) + quarto_render(file, ..., output_format = format, metadata = meta) } } From ddc41d46987ffdf94d01107d793231fe1df0b559 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 3 Nov 2023 15:30:00 +0100 Subject: [PATCH 06/30] devtools::build_vignettes --- .Rbuildignore | 2 ++ .gitignore | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 8410e7f..d33f5a2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,5 @@ ^\.github$ ^\.vscode$ ^\.quarto$ +^doc$ +^Meta$ diff --git a/.gitignore b/.gitignore index bb5bb7b..8ffba7c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ inst/doc docs /.quarto/ +/doc/ +/Meta/ From fe9374ffde8536f263d5f35b6f17886bf4d61c8e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 7 Nov 2023 18:18:10 +0100 Subject: [PATCH 07/30] Add system_file from staticimports --- R/staticimports.R | 88 +++++++++++++++++++++++++++++++++++++++++++++++ R/utils.R | 3 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 R/staticimports.R diff --git a/R/staticimports.R b/R/staticimports.R new file mode 100644 index 0000000..7fbcb75 --- /dev/null +++ b/R/staticimports.R @@ -0,0 +1,88 @@ +# Generated by staticimports; do not edit by hand. +# ====================================================================== +# Imported from pkg:staticimports +# ====================================================================== + +# Borrowed from pkgload:::dev_meta, with some modifications. +# Returns TRUE if `pkg` was loaded with `devtools::load_all()`. +devtools_loaded <- function(pkg) { + ns <- .getNamespace(pkg) + if (is.null(ns) || is.null(ns$.__DEVTOOLS__)) { + return(FALSE) + } + TRUE +} + +# Borrowed from pkgload::shim_system.file, with some modifications. This behaves +# like `system.file()`, except that (1) for packages loaded with +# `devtools::load_all()`, it will return the path to files in the package's +# inst/ directory, and (2) for other packages, the directory lookup is cached. +# Also, to keep the implementation simple, it doesn't support specification of +# lib.loc or mustWork. +system_file <- function(..., package = "base") { + if (!devtools_loaded(package)) { + return(system_file_cached(..., package = package)) + } + + if (!is.null(names(list(...)))) { + stop("All arguments other than `package` must be unnamed.") + } + + # If package was loaded with devtools (the package loaded with load_all), + # also search for files under inst/, and don't cache the results (it seems + # more likely that the package path will change during the development + # process) + pkg_path <- find.package(package) + + # First look in inst/ + files_inst <- file.path(pkg_path, "inst", ...) + present_inst <- file.exists(files_inst) + + # For any files that weren't present in inst/, look in the base path + files_top <- file.path(pkg_path, ...) + present_top <- file.exists(files_top) + + # Merge them together. Here are the different possible conditions, and the + # desired result. NULL means to drop that element from the result. + # + # files_inst: /inst/A /inst/B /inst/C /inst/D + # present_inst: T T F F + # files_top: /A /B /C /D + # present_top: T F T F + # result: /inst/A /inst/B /C NULL + # + files <- files_top + files[present_inst] <- files_inst[present_inst] + # Drop cases where not present in either location + files <- files[present_inst | present_top] + if (length(files) == 0) { + return("") + } + # Make sure backslashes are replaced with slashes on Windows + normalizePath(files, winslash = "/") +} + +# A wrapper for `system.file()`, which caches the package path because +# `system.file()` can be slow. If a package is not installed, the result won't +# be cached. +system_file_cached <- local({ + pkg_dir_cache <- character() + + function(..., package = "base") { + if (!is.null(names(list(...)))) { + stop("All arguments other than `package` must be unnamed.") + } + + not_cached <- is.na(match(package, names(pkg_dir_cache))) + if (not_cached) { + pkg_dir <- system.file(package = package) + if (nzchar(pkg_dir)) { + pkg_dir_cache[[package]] <<- pkg_dir + } + } else { + pkg_dir <- pkg_dir_cache[[package]] + } + + file.path(pkg_dir, ...) + } +}) diff --git a/R/utils.R b/R/utils.R index 7539be3..6b650fb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,4 +1,5 @@ - +# @staticimports pkg:staticimports +# system_file relative_to_wd <- function(path) { relative_to(getwd(), path) From 587183caaac7849d74c225dcd1961874c7015c35 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 7 Nov 2023 18:23:53 +0100 Subject: [PATCH 08/30] Set some meta for html vignette to enforce lightweight html for CRAN Size of package's file on CRAN is limited and controled. quarto:html engine should provide a lightweight version by default * embed-resources: true -> a single HTML file as vignette * minimal: true & theme: 'none' -> no boostrap related feature * a custom CSS based on rmarkdown::html_vignettes() Setting those metadata means it won't be possible to overwrite as they are overrinding any in YAML header settings. --- R/utils-vignettes.R | 24 ++- .../quarto_vignette/resources/vignette.css | 158 ++++++++++++++++++ vignettes/publishing.qmd | 4 +- 3 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 inst/rmarkdown/template/quarto_vignette/resources/vignette.css diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index 45b65c3..8d1bd7e 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -17,9 +17,29 @@ vig_engine <- function(..., quarto_format) { } vweave_quarto <- function(format) { - meta <- list() - meta["embed-resources"] <- TRUE + meta <- get_meta(format) function(file, driver, syntax, encoding, quiet = FALSE, ...) { quarto_render(file, ..., output_format = format, metadata = meta) } } + +get_meta <- function(format) { + if (format == "html") { + return(get_meta_for_html()) + } +} + +get_meta_for_html <- function() { + + css <- system_file("rmarkdown", "template", "quarto_vignette" ,"resources", + "vignette.css", package = "quarto") + meta <- list() + meta$format$html <- + list( + `embed-resources` = TRUE, + minimal = TRUE, + theme = "none", + css = css + ) + meta +} diff --git a/inst/rmarkdown/template/quarto_vignette/resources/vignette.css b/inst/rmarkdown/template/quarto_vignette/resources/vignette.css new file mode 100644 index 0000000..c5a5782 --- /dev/null +++ b/inst/rmarkdown/template/quarto_vignette/resources/vignette.css @@ -0,0 +1,158 @@ +body { + background-color: #fff; + margin: 1em auto; + max-width: 700px; + overflow: visible; + padding-left: 2em; + padding-right: 2em; + font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 14px; + line-height: 1.35; +} + + + +table { + margin: 1em auto; + border-width: 1px; + border-color: #DDDDDD; + border-style: outset; + border-collapse: collapse; +} +table th { + border-width: 2px; + padding: 5px; + border-style: inset; +} +table td { + border-width: 1px; + border-style: inset; + line-height: 18px; + padding: 5px 5px; +} +table, table th, table td { + border-left-style: none; + border-right-style: none; +} +table thead, table tr.even { + background-color: #f7f7f7; +} + +p { + margin: 0.5em 0; +} + +blockquote { + background-color: #f6f6f6; + padding: 0.25em 0.75em; +} + +hr { + border-style: solid; + border: none; + border-top: 1px solid #777; + margin: 28px 0; +} + +dl { + margin-left: 0; +} +dl dd { + margin-bottom: 13px; + margin-left: 13px; +} +dl dt { + font-weight: bold; +} + +ul { + margin-top: 0; +} +ul li { + list-style: circle outside; +} +ul ul { + margin-bottom: 0; +} + +pre, code { + background-color: #f7f7f7; + border-radius: 3px; + color: #333; + white-space: pre-wrap; /* Wrap long lines */ +} +pre { + border-radius: 3px; + margin: 5px 0px 10px 0px; + padding: 10px; +} +pre:not([class]) { + background-color: #f7f7f7; +} + +code { + font-family: Consolas, Monaco, 'Courier New', monospace; + font-size: 85%; +} +p > code, li > code { + padding: 2px 0px; +} + +div.figure { + text-align: center; +} +img { + background-color: #FFFFFF; + padding: 2px; + border: 1px solid #DDDDDD; + border-radius: 3px; + border: 1px solid #CCCCCC; + margin: 0 5px; +} + +h1 { + margin-top: 0; + font-size: 35px; + line-height: 40px; +} + +h2 { + border-bottom: 4px solid #f7f7f7; + padding-top: 10px; + padding-bottom: 2px; + font-size: 145%; +} + +h3 { + border-bottom: 2px solid #f7f7f7; + padding-top: 10px; + font-size: 120%; +} + +h4 { + border-bottom: 1px solid #f7f7f7; + margin-left: 8px; + font-size: 105%; +} + +h5, h6 { + border-bottom: 1px solid #ccc; + font-size: 105%; +} + +a { + color: #0033dd; + text-decoration: none; +} +a:hover { + color: #6666ff; } +a:visited { + color: #800080; } +a:visited:hover { + color: #BB00BB; } +a[href^="http:"] { + text-decoration: underline; } +a[href^="https:"] { + text-decoration: underline; } + + diff --git a/vignettes/publishing.qmd b/vignettes/publishing.qmd index ca9d0d6..8932137 100644 --- a/vignettes/publishing.qmd +++ b/vignettes/publishing.qmd @@ -1,8 +1,6 @@ --- title: "Publishing" -format: - html: - minimal: false +format: html vignette: > %\VignetteIndexEntry{Publishing} %\VignetteEngine{quarto::html} From 6c490d273c075e62880dacd87f47261ad967b664 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 22 Dec 2023 13:40:10 +0100 Subject: [PATCH 09/30] USe html vignette in the package --- vignettes/hello.qmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index bd4a093..d45adaf 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -7,7 +7,7 @@ format: toc: true vignette: > %\VignetteIndexEntry{Vignettes} - %\VignetteEngine{quarto::pdf} + %\VignetteEngine{quarto::html} %\VignetteEncoding{UTF-8} --- From 007b9537b6d7bca41afe1089774f76f10a8ec92b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 11:24:16 +0100 Subject: [PATCH 10/30] typo --- R/utils-vignettes.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index 8d1bd7e..797bb95 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -31,7 +31,7 @@ get_meta <- function(format) { get_meta_for_html <- function() { - css <- system_file("rmarkdown", "template", "quarto_vignette" ,"resources", + css <- system_file("rmarkdown", "template", "quarto_vignette", "resources", "vignette.css", package = "quarto") meta <- list() meta$format$html <- From 54401e56bbd34afd75c7e04ad4e768b4af89799f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 11:24:38 +0100 Subject: [PATCH 11/30] Same entry index as Title --- vignettes/hello.qmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index d45adaf..7f211a4 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -6,7 +6,7 @@ format: html: toc: true vignette: > - %\VignetteIndexEntry{Vignettes} + %\VignetteIndexEntry{Quarto Vignettes} %\VignetteEngine{quarto::html} %\VignetteEncoding{UTF-8} --- From 31c1eb93f17facdcec9006fd951d3b51dafc1a93 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 11:58:05 +0100 Subject: [PATCH 12/30] Explain in demo vignette the HTML quarto engine --- vignettes/hello.qmd | 60 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index 7f211a4..87fe99f 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -11,26 +11,60 @@ vignette: > %\VignetteEncoding{UTF-8} --- -## Hello Vignette World! +This is an example Quarto vignette, demonstrating how the **quarto** package can let you write R package vignettes with Quarto (). -This is an example Quarto vignette, demonstrating how the **quarto** package can let you write package vignettes in Quarto. +## Vignette Engines -## Two Vignette Engines +The **quarto** R package registers vignette engines that can be used in `%\VignetteEngine{}` directives in vignette headers. + +To learn more about how vignettes engine works, and how to write vignette engines, see the [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and the [R Packages (2e)](https://r-pkgs.org/vignettes.html) book. + + +### HTML + +Add this to your YAML header -The **quarto** package registers 2 vignette engines, `quarto::pdf` and `quarto::html`. Either of these may be selected in a Quarto vignette's YAML header. For example, this vignette's header reads: ```yaml +vignette: > + %\VignetteIndexEntry{Vignette's Title} + %\VignetteEngine{quarto::html} + %\VignetteEncoding{UTF-8} --- -title: "Quarto Vignettes" -format: - pdf: - toc: false +``` + +This will build a HTML document using Quarto, suitable for using as vignette to publish on CRAN. Choice has been made to create a very minimal HTML vignette by default, and so it is built with the following changes based to Quarto's `format: html` defaults: + +- The HTML file produced is standalone (i.e. [`embed-resources: true`](https://quarto.org/docs/output-formats/html-publishing.html#standalone-html)) +- Bootstrap has been disabled (i.e. [`theme: none`](https://quarto.org/docs/output-formats/html-themes.html) and [`minimal: true`](https://quarto.org/docs/output-formats/html-basics.html#minimal-html)) +- A custom CSS file is provided. + +This is equivalent to + +```yaml +format: + html: + theme: none + minimal: true + embed-resources: true + css: custom.css +``` + +All those configurations are set in way that they can't be override by YAML header in the vignette source file. Only new configuration can be set, e.g adding a Table Of Content: + +````yaml +format: html: toc: true vignette: > - %\VignetteIndexEntry{Vignettes} - %\VignetteEngine{quarto::pdf} + %\VignetteIndexEntry{Vignette's Title} + %\VignetteEngine{quarto::html} %\VignetteEncoding{UTF-8} ---- -``` +```` + +This is one limitation of the current implementation of the vignette engine. This is to insure HTML vignette produced are reasonable in size and can be published on CRAN without problem. + +The other limitation concerns the interactive rendering. If you render your vignette `.qmd` file using `quarto render` or any other function, the output will be based on default HTML format from Quarto and not the vignette engine one. Only building the vignette will produce the real results. More about building vignette in the [R Packages (2e)](https://r-pkgs.org/vignettes.html#sec-vignettes-how-built-checked) book. + + + -Consequently, a PDF version of this vignette is built. From c9c2c7aba01688c01f6692ece0bd61a3ae2fc860 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 12:04:39 +0100 Subject: [PATCH 13/30] Typo --- R/render.R | 2 +- man/quarto_render.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/render.R b/R/render.R index 3282886..d15d1c7 100644 --- a/R/render.R +++ b/R/render.R @@ -34,7 +34,7 @@ #' This will be merged over `metadata-file` options if both are #' specified. #' @param metadata_file A yaml file passed to `--metadata-file` CLI flags to -#' overrite metadata. This will be merged with `metadata` if both are +#' override metadata. This will be merged with `metadata` if both are #' specified, with low precedence on `metadata` options. #' @param debug Leave intermediate files in place after render. #' @param quiet Suppress warning and other messages. diff --git a/man/quarto_render.Rd b/man/quarto_render.Rd index 0c14a51..f16d112 100644 --- a/man/quarto_render.Rd +++ b/man/quarto_render.Rd @@ -71,7 +71,7 @@ This will be merged over \code{metadata-file} options if both are specified.} \item{metadata_file}{A yaml file passed to \code{--metadata-file} CLI flags to -overrite metadata. This will be merged with \code{metadata} if both are +override metadata. This will be merged with \code{metadata} if both are specified, with low precedence on \code{metadata} options.} \item{debug}{Leave intermediate files in place after render.} From c88a0e308a4d97c41630fb8a60536cce2f286bbe Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 12:12:38 +0100 Subject: [PATCH 14/30] Handle NULL in format --- R/utils-vignettes.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index 797bb95..f0049a6 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -24,6 +24,7 @@ vweave_quarto <- function(format) { } get_meta <- function(format) { + if (is.null(format)) return(NULL) if (format == "html") { return(get_meta_for_html()) } From 00baa226045f29573a9d7fc8f4b11804aaea74d4 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 12:12:57 +0100 Subject: [PATCH 15/30] Add mention of quarto::pdf engine --- vignettes/hello.qmd | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index 87fe99f..6d1679e 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -66,5 +66,20 @@ This is one limitation of the current implementation of the vignette engine. Thi The other limitation concerns the interactive rendering. If you render your vignette `.qmd` file using `quarto render` or any other function, the output will be based on default HTML format from Quarto and not the vignette engine one. Only building the vignette will produce the real results. More about building vignette in the [R Packages (2e)](https://r-pkgs.org/vignettes.html#sec-vignettes-how-built-checked) book. +### PDF +Add this to your YAML header + +```yaml +format: + pdf: + toc: false +vignette: > + %\VignetteIndexEntry{Vignette's Title} + %\VignetteEngine{quarto::pdf} + %\VignetteEncoding{UTF-8} +--- +``` + +the vignette built will be a PDF vignette using Quarto's defaults for `format: pdf` format, with only Table Of Content opted-out. This format will be using LaTeX to build the PDF, and so you will need to take precaution for a CRAN vignette. Refers to [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and CRAN policy. From c2b5eecaa0d3a3071c725b6c555fb56153a59082 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 12:24:02 +0100 Subject: [PATCH 16/30] Split HTML and PDF vignette --- vignettes/hello-pdf.qmd | 35 +++++++++++++++++++++++++++++++++++ vignettes/hello.qmd | 25 ++----------------------- 2 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 vignettes/hello-pdf.qmd diff --git a/vignettes/hello-pdf.qmd b/vignettes/hello-pdf.qmd new file mode 100644 index 0000000..808f384 --- /dev/null +++ b/vignettes/hello-pdf.qmd @@ -0,0 +1,35 @@ +--- +title: "Quarto Vignettes" +format: + pdf: + toc: false +vignette: > + %\VignetteIndexEntry{Quarto Vignettes} + %\VignetteEngine{quarto::html} + %\VignetteEncoding{UTF-8} +--- + +This is an example Quarto PDF vignette. + +## PDF Vignette Engines + +The **quarto** R package registers vignette engines that can be used in `%\VignetteEngine{}` directives in vignette headers. + +To learn more about how vignettes engine works, and how to write vignette engines, see the [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and the [R Packages (2e)](https://r-pkgs.org/vignettes.html) book. + + +To produce a PDF vignette engine, add this to your YAML header + +```yaml +format: + pdf: + toc: false +vignette: > + %\VignetteIndexEntry{Vignette's Title} + %\VignetteEngine{quarto::pdf} + %\VignetteEncoding{UTF-8} +--- +``` + +the vignette built will be a PDF vignette using Quarto's defaults for `format: pdf` format, with only Table Of Content opted-out. This format will be using LaTeX to build the PDF, and so you will need to take precaution for a CRAN vignette. Refers to [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and CRAN policy. + diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index 6d1679e..2bba2f7 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -1,8 +1,6 @@ --- title: "Quarto Vignettes" format: - pdf: - toc: false html: toc: true vignette: > @@ -13,16 +11,14 @@ vignette: > This is an example Quarto vignette, demonstrating how the **quarto** package can let you write R package vignettes with Quarto (). -## Vignette Engines +## HTML Vignette Engines The **quarto** R package registers vignette engines that can be used in `%\VignetteEngine{}` directives in vignette headers. To learn more about how vignettes engine works, and how to write vignette engines, see the [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and the [R Packages (2e)](https://r-pkgs.org/vignettes.html) book. -### HTML - -Add this to your YAML header +To produce a HTML vignette engine, add this to your YAML header ```yaml vignette: > @@ -66,20 +62,3 @@ This is one limitation of the current implementation of the vignette engine. Thi The other limitation concerns the interactive rendering. If you render your vignette `.qmd` file using `quarto render` or any other function, the output will be based on default HTML format from Quarto and not the vignette engine one. Only building the vignette will produce the real results. More about building vignette in the [R Packages (2e)](https://r-pkgs.org/vignettes.html#sec-vignettes-how-built-checked) book. -### PDF - -Add this to your YAML header - -```yaml -format: - pdf: - toc: false -vignette: > - %\VignetteIndexEntry{Vignette's Title} - %\VignetteEngine{quarto::pdf} - %\VignetteEncoding{UTF-8} ---- -``` - -the vignette built will be a PDF vignette using Quarto's defaults for `format: pdf` format, with only Table Of Content opted-out. This format will be using LaTeX to build the PDF, and so you will need to take precaution for a CRAN vignette. Refers to [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and CRAN policy. - From 37e8df11ad9434143cac8c1abad286a5440fede8 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 12:35:40 +0100 Subject: [PATCH 17/30] Correct vignette format --- vignettes/hello-pdf.qmd | 6 +++--- vignettes/hello.qmd | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vignettes/hello-pdf.qmd b/vignettes/hello-pdf.qmd index 808f384..f187c55 100644 --- a/vignettes/hello-pdf.qmd +++ b/vignettes/hello-pdf.qmd @@ -1,11 +1,11 @@ --- -title: "Quarto Vignettes" +title: "Quarto PDF Vignettes" format: pdf: toc: false vignette: > - %\VignetteIndexEntry{Quarto Vignettes} - %\VignetteEngine{quarto::html} + %\VignetteIndexEntry{Quarto PDF Vignettes} + %\VignetteEngine{quarto::pdf} %\VignetteEncoding{UTF-8} --- diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index 2bba2f7..c7be477 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -1,10 +1,10 @@ --- -title: "Quarto Vignettes" +title: "Quarto HTML Vignettes" format: html: toc: true vignette: > - %\VignetteIndexEntry{Quarto Vignettes} + %\VignetteIndexEntry{Quarto HTML Vignettes} %\VignetteEngine{quarto::html} %\VignetteEncoding{UTF-8} --- From be0d20b908444361dcea0e39e98e524de1f12627 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 13:39:46 +0100 Subject: [PATCH 18/30] Update doc regarding maintainer change --- man/quarto-package.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/quarto-package.Rd b/man/quarto-package.Rd index eb47183..f6656ba 100644 --- a/man/quarto-package.Rd +++ b/man/quarto-package.Rd @@ -18,11 +18,11 @@ Useful links: } \author{ -\strong{Maintainer}: JJ Allaire \email{jj@rstudio.com} (\href{https://orcid.org/0000-0003-0174-9868}{ORCID}) +\strong{Maintainer}: Christophe Dervieux \email{cderv@posit.co} (\href{https://orcid.org/0000-0003-4474-2498}{ORCID}) Authors: \itemize{ - \item Christophe Dervieux \email{cderv@posit.co} (\href{https://orcid.org/0000-0003-4474-2498}{ORCID}) + \item JJ Allaire \email{jj@posit.co} (\href{https://orcid.org/0000-0003-0174-9868}{ORCID}) } } From df248ac78b05be7b41626d7fe60292ac0212c138 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 15:34:05 +0100 Subject: [PATCH 19/30] install the package itself as we register vignette engine R will check for engine at build time. https://github.com/wch/r-source/blob/ed93ccd03e1bfa5794348faf32bfd1bc4aa3d547/src/library/tools/R/build.R#L283-L285 Causing error ``` Error in loadVignetteBuilder(pkgdir, TRUE) : vignette builder 'quarto' not found ``` --- .github/workflows/R-CMD-check.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 39906e4..8cae474 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -62,7 +62,8 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck + # install the package itself as we register vignette engine + extra-packages: any::rcmdcheck, local::. needs: check - uses: r-lib/actions/check-r-package@v2 From 1990405e0c412d0c68a89276a4071613b49ca7bd Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 15:58:05 +0100 Subject: [PATCH 20/30] Add LaTeX install --- .github/workflows/R-CMD-check.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 8cae474..8f8aa92 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -50,6 +50,8 @@ jobs: - uses: quarto-dev/quarto-actions/setup@v2 with: version: ${{ matrix.config.quarto || 'release' }} + tinytex: true + # replace with setting up QUARTO Pandoc for rmarkdown - uses: r-lib/actions/setup-pandoc@v2 From d3ca56e20ad17c5d83e654fcd56e7359b4c32b61 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 17:38:22 +0100 Subject: [PATCH 21/30] Ignore intermediate directories that would be produced by a author mode render --- .Rbuildignore | 2 ++ vignettes/.gitignore | 1 + vignettes/hello.qmd | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index d33f5a2..3663461 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,5 @@ ^\.quarto$ ^doc$ ^Meta$ + +^vignettes/*_files$ diff --git a/vignettes/.gitignore b/vignettes/.gitignore index 097b241..ba7abf3 100644 --- a/vignettes/.gitignore +++ b/vignettes/.gitignore @@ -1,2 +1,3 @@ *.html *.R +*_files diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index c7be477..1fdce5a 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -61,4 +61,9 @@ This is one limitation of the current implementation of the vignette engine. Thi The other limitation concerns the interactive rendering. If you render your vignette `.qmd` file using `quarto render` or any other function, the output will be based on default HTML format from Quarto and not the vignette engine one. Only building the vignette will produce the real results. More about building vignette in the [R Packages (2e)](https://r-pkgs.org/vignettes.html#sec-vignettes-how-built-checked) book. +Intermediates resources that would be created by an authoring workflow that would `quarto render` with default `format: html` should be ignored in package sources. + +- Added to `.Rbuildignore` (e.g `usethis::use_build_ignore("vignettes/*_files")`) +- Added to `.gitignore` (e.g. `usethis::use_git_ignore("*_files", "vignettes")`) + From edf2f4c6a4244430fef817913634da3342696c7f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 17:59:45 +0100 Subject: [PATCH 22/30] Remove knitr as vignettebuilder dependency --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ee78b25..f734864 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,6 @@ Suggests: withr, xfun VignetteBuilder: - knitr, quarto Config/testthat/edition: 3 Encoding: UTF-8 From 636324d4664b912cbee52f323ed0b0e069da63ba Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 18:00:20 +0100 Subject: [PATCH 23/30] Use include to share doc and show example on how to do it --- vignettes/.install_extras | 1 + vignettes/hello-pdf.qmd | 2 +- vignettes/hello.qmd | 5 +---- vignettes/include/_intro.qmd | 10 ++++++++++ 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 vignettes/.install_extras create mode 100644 vignettes/include/_intro.qmd diff --git a/vignettes/.install_extras b/vignettes/.install_extras new file mode 100644 index 0000000..a1a869c --- /dev/null +++ b/vignettes/.install_extras @@ -0,0 +1 @@ +include diff --git a/vignettes/hello-pdf.qmd b/vignettes/hello-pdf.qmd index f187c55..d120694 100644 --- a/vignettes/hello-pdf.qmd +++ b/vignettes/hello-pdf.qmd @@ -9,7 +9,7 @@ vignette: > %\VignetteEncoding{UTF-8} --- -This is an example Quarto PDF vignette. +{{< include include/_intro.qmd >}} ## PDF Vignette Engines diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index 1fdce5a..3cb9ac8 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -1,15 +1,12 @@ --- title: "Quarto HTML Vignettes" -format: - html: - toc: true vignette: > %\VignetteIndexEntry{Quarto HTML Vignettes} %\VignetteEngine{quarto::html} %\VignetteEncoding{UTF-8} --- -This is an example Quarto vignette, demonstrating how the **quarto** package can let you write R package vignettes with Quarto (). +{{< include include/_intro.qmd >}} ## HTML Vignette Engines diff --git a/vignettes/include/_intro.qmd b/vignettes/include/_intro.qmd new file mode 100644 index 0000000..6f65a33 --- /dev/null +++ b/vignettes/include/_intro.qmd @@ -0,0 +1,10 @@ +This is an example Quarto vignette, demonstrating how the **quarto** package can let you write R package vignettes with Quarto (). + +## Quarto as vignette builder + +Add this to your `DESCRIPTION` file: + +```dcf +VignetteBuilder: + quarto +``` From 3c58e07da7bbcc10dccddc6f7cea97e5fb090fd4 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 18:00:31 +0100 Subject: [PATCH 24/30] Add toc to publishing --- vignettes/publishing.qmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vignettes/publishing.qmd b/vignettes/publishing.qmd index 8932137..92003bd 100644 --- a/vignettes/publishing.qmd +++ b/vignettes/publishing.qmd @@ -1,6 +1,8 @@ --- title: "Publishing" -format: html +format: + html: + toc: true vignette: > %\VignetteIndexEntry{Publishing} %\VignetteEngine{quarto::html} From d2b0ed96ed43938b9ca95862f8ac85c0c8d61e04 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 20:27:26 +0100 Subject: [PATCH 25/30] Remove extra characters --- vignettes/hello-pdf.qmd | 1 - 1 file changed, 1 deletion(-) diff --git a/vignettes/hello-pdf.qmd b/vignettes/hello-pdf.qmd index d120694..db81677 100644 --- a/vignettes/hello-pdf.qmd +++ b/vignettes/hello-pdf.qmd @@ -28,7 +28,6 @@ vignette: > %\VignetteIndexEntry{Vignette's Title} %\VignetteEngine{quarto::pdf} %\VignetteEncoding{UTF-8} ---- ``` the vignette built will be a PDF vignette using Quarto's defaults for `format: pdf` format, with only Table Of Content opted-out. This format will be using LaTeX to build the PDF, and so you will need to take precaution for a CRAN vignette. Refers to [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and CRAN policy. From 5c64a1d6311beb46df1c60b902f1ed1a3e3d2992 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 30 Jan 2024 20:29:13 +0100 Subject: [PATCH 26/30] Register a generic engine that will use whatever is defined in format yaml key This is for advanced usage, and allows to override defaults. User is responsible to produce vignette with controlled size and reproducible --- R/utils-vignettes.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index f0049a6..fdf88e7 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -1,6 +1,7 @@ register_vignette_engines <- function(pkg) { vig_engine("html", quarto_format = "html") vig_engine("pdf", quarto_format = "pdf") + vig_engine("format", quarto_format = NULL) } From 5e3c222e0f969c360faf06a7f585ad1d734c8c9d Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 31 Jan 2024 14:30:46 +0100 Subject: [PATCH 27/30] Remove usage of staticimport system_files --- R/staticimports.R | 88 --------------------------------------------- R/utils-vignettes.R | 2 +- R/utils.R | 2 -- 3 files changed, 1 insertion(+), 91 deletions(-) delete mode 100644 R/staticimports.R diff --git a/R/staticimports.R b/R/staticimports.R deleted file mode 100644 index 7fbcb75..0000000 --- a/R/staticimports.R +++ /dev/null @@ -1,88 +0,0 @@ -# Generated by staticimports; do not edit by hand. -# ====================================================================== -# Imported from pkg:staticimports -# ====================================================================== - -# Borrowed from pkgload:::dev_meta, with some modifications. -# Returns TRUE if `pkg` was loaded with `devtools::load_all()`. -devtools_loaded <- function(pkg) { - ns <- .getNamespace(pkg) - if (is.null(ns) || is.null(ns$.__DEVTOOLS__)) { - return(FALSE) - } - TRUE -} - -# Borrowed from pkgload::shim_system.file, with some modifications. This behaves -# like `system.file()`, except that (1) for packages loaded with -# `devtools::load_all()`, it will return the path to files in the package's -# inst/ directory, and (2) for other packages, the directory lookup is cached. -# Also, to keep the implementation simple, it doesn't support specification of -# lib.loc or mustWork. -system_file <- function(..., package = "base") { - if (!devtools_loaded(package)) { - return(system_file_cached(..., package = package)) - } - - if (!is.null(names(list(...)))) { - stop("All arguments other than `package` must be unnamed.") - } - - # If package was loaded with devtools (the package loaded with load_all), - # also search for files under inst/, and don't cache the results (it seems - # more likely that the package path will change during the development - # process) - pkg_path <- find.package(package) - - # First look in inst/ - files_inst <- file.path(pkg_path, "inst", ...) - present_inst <- file.exists(files_inst) - - # For any files that weren't present in inst/, look in the base path - files_top <- file.path(pkg_path, ...) - present_top <- file.exists(files_top) - - # Merge them together. Here are the different possible conditions, and the - # desired result. NULL means to drop that element from the result. - # - # files_inst: /inst/A /inst/B /inst/C /inst/D - # present_inst: T T F F - # files_top: /A /B /C /D - # present_top: T F T F - # result: /inst/A /inst/B /C NULL - # - files <- files_top - files[present_inst] <- files_inst[present_inst] - # Drop cases where not present in either location - files <- files[present_inst | present_top] - if (length(files) == 0) { - return("") - } - # Make sure backslashes are replaced with slashes on Windows - normalizePath(files, winslash = "/") -} - -# A wrapper for `system.file()`, which caches the package path because -# `system.file()` can be slow. If a package is not installed, the result won't -# be cached. -system_file_cached <- local({ - pkg_dir_cache <- character() - - function(..., package = "base") { - if (!is.null(names(list(...)))) { - stop("All arguments other than `package` must be unnamed.") - } - - not_cached <- is.na(match(package, names(pkg_dir_cache))) - if (not_cached) { - pkg_dir <- system.file(package = package) - if (nzchar(pkg_dir)) { - pkg_dir_cache[[package]] <<- pkg_dir - } - } else { - pkg_dir <- pkg_dir_cache[[package]] - } - - file.path(pkg_dir, ...) - } -}) diff --git a/R/utils-vignettes.R b/R/utils-vignettes.R index fdf88e7..80810f7 100644 --- a/R/utils-vignettes.R +++ b/R/utils-vignettes.R @@ -33,7 +33,7 @@ get_meta <- function(format) { get_meta_for_html <- function() { - css <- system_file("rmarkdown", "template", "quarto_vignette", "resources", + css <- system.file("rmarkdown", "template", "quarto_vignette", "resources", "vignette.css", package = "quarto") meta <- list() meta$format$html <- diff --git a/R/utils.R b/R/utils.R index 6b650fb..d314c79 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,5 +1,3 @@ -# @staticimports pkg:staticimports -# system_file relative_to_wd <- function(path) { relative_to(getwd(), path) From 0c6e443df29fb2b87e7a2a4ef30cf837f0da2d77 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 31 Jan 2024 14:42:16 +0100 Subject: [PATCH 28/30] Add NEWS bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index e30be26..356b439 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # quarto (development version) +- Add registration of vignette engine to use `quarto` as a vignette builder, and use `.qmd` file as vignette. See `vignette("hello", package = "quarto")`. (thanks, @dcnorris, #57). + - Add `quarto_binary_sitrep()` to check possible difference in Quarto binary used by this package, and the one used by RStudio IDE (thanks, @jthomasmock, #12). - Add `quarto_create_project()` function that calls `quarto create project ` (thanks, @maelle, #87). From 6ccc3b1ce3aeea4958c91732b4d5c4e42b9fa6bc Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 31 Jan 2024 14:57:06 +0100 Subject: [PATCH 29/30] Go back to v2.6.7 for now as there is conflict in naming follwing update --- .github/workflows/R-CMD-check.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 8f8aa92..aebf007 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -54,20 +54,20 @@ jobs: # replace with setting up QUARTO Pandoc for rmarkdown - - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-pandoc@v2.6.5 - - uses: r-lib/actions/setup-r@v2 + - uses: r-lib/actions/setup-r@v2.6.5 with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v2 + - uses: r-lib/actions/setup-r-dependencies@v2.6.5 with: # install the package itself as we register vignette engine extra-packages: any::rcmdcheck, local::. needs: check - - uses: r-lib/actions/check-r-package@v2 + - uses: r-lib/actions/check-r-package@v2.6.5 with: upload-snapshots: true From e6c7360c1f5d1b8a5c3539c223a1f9a7626a7cd1 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 31 Jan 2024 17:16:46 +0100 Subject: [PATCH 30/30] Bump version [skip ci] --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f734864..87b2d41 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: quarto Title: R Interface to 'Quarto' Markdown Publishing System -Version: 1.3.11 +Version: 1.3.12 Authors@R: c( person("JJ", "Allaire", , "jj@posit.co", role = "aut", comment = c(ORCID = "0000-0003-0174-9868")),