preview_rd: Preview rendered version of an Rd file

Description Usage Arguments Details Note Author(s) Examples

View source: R/preview_rd.r

Description

Function to preview the rendered version of an Rd file.

Usage

1
preview_rd(Rdfile, view = TRUE, type = "html", verbose = FALSE, dark = FALSE)

Arguments

Rdfile

character string with the name of the Rd file to preview (either with or without the .Rd or .rd extension).

view

logical indicating whether the rendered version of the help file should be displayed.

type

character string indicating which version should be rendered (either "html", "txt", or "pdf").

verbose

logical indicating whether diagnostic output will be shown.

dark

logical indicating whether the rendererd HTML page should use a dark mode.

Details

The function is useful when writing a help file that contains MathJax equations. Instead of having to reinstall the package under development to check if the equations are being rendered correctly, one can just set the current working directory to the root of the package (or its man directory) and then use preview_rd() to preview the HTML, plain-text, or PDF version of an Rd file on the fly.

For type="html", the HTML page will be opened in the browser with the browseURL function. When making further changes to the Rd file, reopening the page each time preview_rd() is called is inconvenient as this will usually open up a new tab in the browser. Setting view=FALSE prevents this. Reloading the page in the open tab should then reflect the updates. In RStudio, the generated HTML version will be displayed in the ‘Viewer’ pane and the view argument is then irrelevant.

Setting dark=TRUE (in combination with type="html") renders the HTML page in dark mode. Unfortunately, this does not work in RStudio.

For type="txt" (or type="text"), the plain-text version of the help file will be shown (using the file.show function and directly on the console in RStudio).

For type="pdf", the PDF is generated using R CMD Rd2pdf and should open up in the default PDF viewer.

Note

Due to some limitations as to how MathJax can be loaded via the mathjaxr package, MathJax must be loaded via the CDN when using the preview_rd() function. Hence, rendering of equations in HTML will only work in the preview with an active internet connection.

Author(s)

Wolfgang Viechtbauer wvb@wvbauer.com https://www.wvbauer.com/

Examples

1
2
3
4
5
## Not run: 
setwd("/path/to/root/of/package")
preview_rd("someRdfile")

## End(Not run)

mathjaxr documentation built on March 1, 2021, 5:08 p.m.