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 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.
# NOT RUN {
setwd("/path/to/root/of/package")
preview_rd("someRdfile")
# }
Run the code above in your browser using DataLab