Skip to contents

Renders a full package reference manual and writes it to a file.

Usage

save_manual(package, output, md_format = md_format_default, wrap = Inf)

Arguments

package

(Scalar character)
The name of an installed package.

output

(Scalar character)
File path where the manual will be written. The extension must be one of .md, .html, or .htm.

md_format

(Scalar character: md_format_default)
Pandoc output format string used for Markdown conversion. Only applies when output has a .md extension. See Pandoc manual for available formats and extensions.

wrap

(Scalar integer: Inf; [1, Inf])
Column width for word wrapping in Markdown output. Inf disables wrapping. Only applies when output has a .md extension.

Value

The value of output, invisibly.

Details

For Markdown output, the function first renders the manual to a temporary HTML file via tools::pkg2HTML(), converts argument tables to HTML definition lists for cleaner Markdown output, then converts to Markdown using Pandoc. Pandoc must be installed and on the system PATH. The default markdown format is:

md_format_default <- paste0(
  "markdown",
  "-raw_html",
  "-inline_code_attributes",
  "-header_attributes",
  "-link_attributes",
  "-native_divs",
  "-native_spans",
  "-auto_identifiers",
  "-fenced_divs",
  "-bracketed_spans",
  "-smart"
)

Examples

#----------------------------------------------------------------------------
# save_manual() example
#----------------------------------------------------------------------------
library(bkmisc)

# Save the tools package manual as markdown
tmp <- tempfile(fileext = ".md")
save_manual("tools", output = tmp)
readLines(tmp) |> head(20)
#>  [1] "# Package {tools}"                             
#>  [2] ""                                              
#>  [3] "## Contents"                                   
#>  [4] ""                                              
#>  [5] "-   [](#tools-package)"                        
#>  [6] ""                                              
#>  [7] "    Tools for Package Development"             
#>  [8] ""                                              
#>  [9] "-   [](#.print.via.format)"                    
#> [10] ""                                              
#> [11] "    Printing Utilities"                        
#> [12] ""                                              
#> [13] "-   [](#CRANtools)"                            
#> [14] ""                                              
#> [15] "    CRAN Package Repository Tools"             
#> [16] ""                                              
#> [17] "-   [](#HTMLheader)"                           
#> [18] ""                                              
#> [19] "    Generate a Standard HTML Header for R Help"
#> [20] ""