Save a package vignette to a file
save_vignette.RdCopies an installed vignette from a package's doc/ directory to a specified file path.
Arguments
- topic
(Scalar character)
The vignette file name, without extension, as listed bytools::getVignetteInfo(package)[, "File"].- package
(Scalar character)
The name of the installed package containing the vignette.- path
(Scalar character)
File path where the vignette will be written. The extension must be.html,.htm,.rmd, or.rnw. Use.htmlor.htmto copy the rendered HTML vignette. Use.rmdor.rnwto copy the vignette source; this is only available for packages installed with their source included (e.g., viadevtools::install()).
Examples
#----------------------------------------------------------------------------
# save_vignette() example
#----------------------------------------------------------------------------
library(bkmisc)
# Check available topics and filenames for dplyr
tools::getVignetteInfo("dplyr")[, "File"]
#> [1] "colwise.Rmd" "grouping.Rmd" "dplyr.Rmd"
#> [4] "programming.Rmd" "recoding-replacing.Rmd" "rowwise.Rmd"
#> [7] "two-table.Rmd" "in-packages.Rmd" "window-functions.Rmd"
#> [10] "base.Rmd"
# Save the desired vignette
tmp <- tempfile(fileext = ".html")
save_vignette("dplyr", package = "dplyr", path = tmp)
readLines(tmp) |> head(20)
#> [1] "<!DOCTYPE html>"
#> [2] ""
#> [3] "<html>"
#> [4] ""
#> [5] "<head>"
#> [6] ""
#> [7] "<meta charset=\"utf-8\" />"
#> [8] "<meta name=\"generator\" content=\"pandoc\" />"
#> [9] "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EDGE\" />"
#> [10] ""
#> [11] "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />"
#> [12] ""
#> [13] ""
#> [14] ""
#> [15] "<title>Introduction to dplyr</title>"
#> [16] ""
#> [17] "<script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to"
#> [18] "// be compatible with the behavior of Pandoc < 2.8)."
#> [19] "document.addEventListener('DOMContentLoaded', function(e) {"
#> [20] " var hs = document.querySelectorAll(\"div.section[class*='level'] > :first-child\");"