From a82e3d1ebdda472f3888acb634c7b604a3588ca1 Mon Sep 17 00:00:00 2001 From: "David C. Norris" Date: Tue, 6 Sep 2022 16:02:16 -0400 Subject: [PATCH 1/5] Register engines quarto::(pdf|html|al) --- DESCRIPTION | 4 ++-- NAMESPACE | 1 + R/zzz.R | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 R/zzz.R diff --git a/DESCRIPTION b/DESCRIPTION index 1ba03c3..ba92a95 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Authors@R: comment = c(ORCID = "0000-0003-0174-9868")) Description: Convert R Markdown documents and 'Jupyter' notebooks to a variety of output formats using 'Quarto'. -Imports: utils,rmarkdown,jsonlite,yaml,processx,rstudioapi,later,rsconnect (>= 0.8.26) +Imports: tools,utils,rmarkdown,jsonlite,yaml,processx,rstudioapi,later,rsconnect (>= 0.8.26) Suggests: knitr, testthat (>= 3.1.0) @@ -21,4 +21,4 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.1 Config/testthat/edition: 3 -VignetteBuilder: knitr +VignetteBuilder: knitr,quarto diff --git a/NAMESPACE b/NAMESPACE index 4ebefa0..1fca235 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,5 +16,6 @@ importFrom(processx,process) 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..6171315 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,35 @@ + +#' Register engines to support Quarto vignettes +#' @importFrom tools vignetteEngine +#' @noRd +.onLoad <- function(libname, pkgname) { # args ignored + ## TODO: Too much duplicated code here! + ## TODO: What to do about the 'encoding' argument? + tools::vignetteEngine(name = "pdf", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "pdf") + }, + tangle = tools::vignetteEngine("knitr::rmarkdown")$tangle, + aspell = tools::vignetteEngine("knitr::rmarkdown")$aspell + ) + tools::vignetteEngine(name = "html", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "html") + }, + tangle = tools::vignetteEngine("knitr::rmarkdown")$tangle, + aspell = tools::vignetteEngine("knitr::rmarkdown")$aspell + ) + tools::vignetteEngine(name = "all", + package = "quarto", + pattern = "[.]qmd$", + weave = function(file, ..., encoding = "UTF-8") { + quarto_render(file, ..., output_format = "all") + }, + tangle = tools::vignetteEngine("knitr::rmarkdown")$tangle, + aspell = tools::vignetteEngine("knitr::rmarkdown")$aspell + ) +} From ea311f047d2a4c45943fc224c47112f2c093060b Mon Sep 17 00:00:00 2001 From: "David C. Norris" Date: Tue, 6 Sep 2022 22:15:25 -0400 Subject: [PATCH 2/5] Drop superfluous tools:: qualification --- R/zzz.R | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 6171315..4807d35 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,33 +3,31 @@ #' @importFrom tools vignetteEngine #' @noRd .onLoad <- function(libname, pkgname) { # args ignored - ## TODO: Too much duplicated code here! - ## TODO: What to do about the 'encoding' argument? - tools::vignetteEngine(name = "pdf", + vignetteEngine(name = "pdf", package = "quarto", pattern = "[.]qmd$", weave = function(file, ..., encoding = "UTF-8") { quarto_render(file, ..., output_format = "pdf") }, - tangle = tools::vignetteEngine("knitr::rmarkdown")$tangle, - aspell = tools::vignetteEngine("knitr::rmarkdown")$aspell + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell ) - tools::vignetteEngine(name = "html", + vignetteEngine(name = "html", package = "quarto", pattern = "[.]qmd$", weave = function(file, ..., encoding = "UTF-8") { quarto_render(file, ..., output_format = "html") }, - tangle = tools::vignetteEngine("knitr::rmarkdown")$tangle, - aspell = tools::vignetteEngine("knitr::rmarkdown")$aspell + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell ) - tools::vignetteEngine(name = "all", + vignetteEngine(name = "all", package = "quarto", pattern = "[.]qmd$", weave = function(file, ..., encoding = "UTF-8") { quarto_render(file, ..., output_format = "all") }, - tangle = tools::vignetteEngine("knitr::rmarkdown")$tangle, - aspell = tools::vignetteEngine("knitr::rmarkdown")$aspell + tangle = vignetteEngine("knitr::rmarkdown")$tangle, + aspell = vignetteEngine("knitr::rmarkdown")$aspell ) } From 89f12185a2484d668a8de521251ec9c34fffe9a3 Mon Sep 17 00:00:00 2001 From: "David C. Norris" Date: Wed, 7 Sep 2022 06:07:38 -0400 Subject: [PATCH 3/5] Remove the "all" vignette engine for simplicity This indulgence in 'speculative generality' was motivated solely by the existence of the 'output_format = "all"' option in quarto_render. In any case, its effect on the package build seems no different from that of "html" engine. --- R/zzz.R | 9 --------- 1 file changed, 9 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 4807d35..ea3fc46 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -21,13 +21,4 @@ tangle = vignetteEngine("knitr::rmarkdown")$tangle, aspell = vignetteEngine("knitr::rmarkdown")$aspell ) - vignetteEngine(name = "all", - package = "quarto", - pattern = "[.]qmd$", - weave = function(file, ..., encoding = "UTF-8") { - quarto_render(file, ..., output_format = "all") - }, - tangle = vignetteEngine("knitr::rmarkdown")$tangle, - aspell = vignetteEngine("knitr::rmarkdown")$aspell - ) } From 4ca88dc3333d5a48fd157bc5c588221d758aeb4a Mon Sep 17 00:00:00 2001 From: "David C. Norris" Date: Wed, 7 Sep 2022 06:22:25 -0400 Subject: [PATCH 4/5] Add example Quarto vignette --- vignettes/hello.qmd | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 vignettes/hello.qmd diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd new file mode 100644 index 0000000..dd3ff29 --- /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. + +## Three 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 6587e41f92c3cf15a624409842486de097c6a6e0 Mon Sep 17 00:00:00 2001 From: "David C. Norris" Date: Wed, 7 Sep 2022 07:48:09 -0400 Subject: [PATCH 5/5] Three --> Two --- vignettes/hello.qmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/hello.qmd b/vignettes/hello.qmd index dd3ff29..bd4a093 100644 --- a/vignettes/hello.qmd +++ b/vignettes/hello.qmd @@ -15,7 +15,7 @@ vignette: > This is an example Quarto vignette, demonstrating how the **quarto** package can let you write package vignettes in Quarto. -## Three Vignette Engines +## 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