preview_rd: Preview rendered version of an Rd file

View source: R/preview_rd.r

preview_rdR Documentation

Preview rendered version of an Rd file


Function to preview the rendered version of an Rd file.


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



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


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


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


logical indicating whether diagnostic output will be shown.


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


other arguments.


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 with preview_rd() 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 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.


Any links to local help pages used in the Rd file to preview will be shown in the rendered HTML or PDF help file, but are non-functional.

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.


Wolfgang Viechtbauer


## Not run: 

## End(Not run)

mathjaxr documentation built on March 18, 2022, 6:39 p.m.