Since R 3.0.0, package vignettes can use non-Sweave engines, and knitr
has provided a few engines to compile vignettes via knit()
with
different templates. See https://yihui.org/knitr/demo/vignette/ for
more information.
If you use the knitr::rmarkdown
engine, please make sure that
you put rmarkdown in the Suggests field of your
DESCRIPTION
file. Also make sure pandoc
is available
during R CMD build
. If you build your package from RStudio, this
is normally not a problem. If you build the package outside RStudio, run
rmarkdown::find_pandoc()
in an R session to check if Pandoc can be
found.
When the rmarkdown package is not installed or not available, or
pandoc
cannot be found, the knitr::rmarkdown
engine will
fall back to the knitr::knitr
engine, which uses R Markdown v1 based
on the markdown package.
library(knitr)
vig_list = tools::vignetteEngine(package = "knitr")
str(vig_list)
#> List of 8
#> $ knitr::rmarkdown :List of 6
#> ..$ name : chr "rmarkdown"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.][Rr](md|markdown)$"
#> ..$ weave :function (...)
#> ..$ tangle :function (file, ..., encoding = "UTF-8", quiet = FALSE)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
#> $ knitr::docco_classic_notangle:List of 6
#> ..$ name : chr "docco_classic_notangle"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.][Rr]mk?d$"
#> ..$ weave :function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE, ...)
#> ..$ tangle :function (file, ...)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
#> $ knitr::docco_linear_notangle :List of 6
#> ..$ name : chr "docco_linear_notangle"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.][Rr](md|markdown)$"
#> ..$ weave :function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE, ...)
#> ..$ tangle :function (file, ...)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
#> $ knitr::knitr :List of 6
#> ..$ name : chr "knitr"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.]([rRsS](nw|tex)|[Rr](md|html|rst))$"
#> ..$ weave :function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE, ...)
#> ..$ tangle :function (file, ..., encoding = "UTF-8", quiet = FALSE)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
#> $ knitr::docco_classic :List of 6
#> ..$ name : chr "docco_classic"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.][Rr]mk?d$"
#> ..$ weave :function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE, ...)
#> ..$ tangle :function (file, ..., encoding = "UTF-8", quiet = FALSE)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
#> $ knitr::rmarkdown_notangle :List of 6
#> ..$ name : chr "rmarkdown_notangle"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.][Rr](md|markdown)$"
#> ..$ weave :function (...)
#> ..$ tangle :function (file, ...)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
#> $ knitr::knitr_notangle :List of 6
#> ..$ name : chr "knitr_notangle"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.]([rRsS](nw|tex)|[Rr](md|html|rst))$"
#> ..$ weave :function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE, ...)
#> ..$ tangle :function (file, ...)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
#> $ knitr::docco_linear :List of 6
#> ..$ name : chr "docco_linear"
#> ..$ package: chr "knitr"
#> ..$ pattern: chr "[.][Rr](md|markdown)$"
#> ..$ weave :function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE, ...)
#> ..$ tangle :function (file, ..., encoding = "UTF-8", quiet = FALSE)
#> ..$ aspell :List of 1
#> .. ..$ filter:function (ifile, encoding = "UTF-8")
vig_list[["knitr::knitr"]][c("weave", "tangle")]
#> $weave
#> function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE,
#> ...)
#> {
#> {
#> on.exit({
#> opts_chunk$restore()
#> knit_hooks$restore()
#> }, add = TRUE)
#> oopts = options(knitr.knit2html.force_v1 = TRUE)
#> on.exit(options(oopts), add = TRUE)
#> }
#> opts_chunk$set(error = FALSE)
#> knit_hooks$set(purl = function(...) {
#> hook_purl(...)
#> for (i in c("optipng", "pngquant")) if (!is.function(knit_hooks$get(i)) &&
#> Sys.which(i) != "") {
#> switch(i, optipng = hook_optipng(...), pngquant = hook_pngquant(...))
#> }
#> })
#> (if (grepl("\\.[Rr]md$", file))
#> knit2html
#> else if (grepl("\\.[Rr]rst$", file))
#> knit2pandoc
#> else knit)(file, encoding = encoding, quiet = quiet, envir = globalenv(),
#> ...)
#> }
#> <bytecode: 0x55c9c21263d8>
#> <environment: namespace:knitr>
#>
#> $tangle
#> function (file, ..., encoding = "UTF-8", quiet = FALSE)
#> {
#> purl(file, encoding = encoding, quiet = quiet, ...)
#> }
#> <bytecode: 0x55c9c212b018>
#> <environment: namespace:knitr>
#>
vig_list[["knitr::knitr_notangle"]][c("weave", "tangle")]
#> $weave
#> function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE,
#> ...)
#> {
#> {
#> on.exit({
#> opts_chunk$restore()
#> knit_hooks$restore()
#> }, add = TRUE)
#> oopts = options(knitr.knit2html.force_v1 = TRUE)
#> on.exit(options(oopts), add = TRUE)
#> }
#> opts_chunk$set(error = FALSE)
#> {
#> }
#> (if (grepl("\\.[Rr]md$", file))
#> knit2html
#> else if (grepl("\\.[Rr]rst$", file))
#> knit2pandoc
#> else knit)(file, encoding = encoding, quiet = quiet, envir = globalenv(),
#> ...)
#> }
#> <environment: namespace:knitr>
#>
#> $tangle
#> function (file, ...)
#> {
#> unlink(with_ext(file, "R"))
#> return()
#> }
#> <bytecode: 0x55c9c214e410>
#> <environment: namespace:knitr>
#>
vig_list[["knitr::docco_classic"]][c("weave", "tangle")]
#> $weave
#> function (file, driver, syntax, encoding = "UTF-8", quiet = FALSE,
#> ...)
#> {
#> {
#> on.exit({
#> opts_chunk$restore()
#> knit_hooks$restore()
#> }, add = TRUE)
#> oopts = options(knitr.knit2html.force_v1 = TRUE)
#> on.exit(options(oopts), add = TRUE)
#> }
#> opts_chunk$set(error = FALSE)
#> knit_hooks$set(purl = function(...) {
#> hook_purl(...)
#> for (i in c("optipng", "pngquant")) if (!is.function(knit_hooks$get(i)) &&
#> Sys.which(i) != "") {
#> switch(i, optipng = hook_optipng(...), pngquant = hook_pngquant(...))
#> }
#> })
#> rocco(file, encoding = encoding, quiet = quiet, envir = globalenv(),
#> ...)
#> }
#> <bytecode: 0x55c9c213a950>
#> <environment: namespace:knitr>
#>
#> $tangle
#> function (file, ..., encoding = "UTF-8", quiet = FALSE)
#> {
#> purl(file, encoding = encoding, quiet = quiet, ...)
#> }
#> <bytecode: 0x55c9c212b018>
#> <environment: namespace:knitr>
#>