I have created an R package following Hadley Wickham's instruction on how to build and document packages with Roxygen. Now I would like to export the function help pages and vignettes to a bunch of html files so that it can also be read and linked-to on a website.
When I look into my library for the installed package there is an html folder but it only contains an 00Index.html
page. Is there an easy way to export the rest (function help pages and vignettes) of my package documentation?
To add documentation to an R package, you need to create a subdirectory “ man ” containing a set of files, one per function, in a special R Documentation format ( . Rd ). These will be the source for the documentation for each function; R processes them to create plain text, PDF, and HTML versions.
R objects are documented in files written in “R documentation” (Rd) format, a simple markup language much of which closely resembles (La)TeX, which can be processed into a variety of formats, including LaTeX, HTML and plain text.
roxygen2 allows you to write specially formatted R comments that generate R documentation files ( man/*. Rd ) and a NAMESPACE file. roxygen2 is used by over 8,000 CRAN packages. Install the latest version of roxygen2 with: install.packages("roxygen2")
Inserting a skeleton - Do this by placing your cursor anywhere in the function you want to document and click Code Tools -> Insert Roxygen Skeleton (default keyboard shortcut Ctrl+Shift+Alt+R ). Populating the skeleton with relevant information.
You could use Hadley Wickham's in-development (i.e not on CRAN) package staticdocs.
Alternatively, if you have the rendered Rd files, you could convert each to HTML using the utility function Rd2HTML
from the tools package that ships with R. Read more about it using ?tools::Rd2HTML
A slight modification of Yihui Xie's function to Build Static HTML Help Pages for R Packages, so that it creates static pages in the package's html directory.
static_help = function(pkg, links = tools::findHTMLlinks()) {
wd <- getwd()
helpdir <- system.file('html', package = "tradeflows")
setwd(helpdir)
message("Generated help files will be placed in ", helpdir)
pkgRdDB = tools:::fetchRdDB(file.path(find.package(pkg),
'help', pkg))
force(links); topics = names(pkgRdDB)
for (p in topics) {
tools::Rd2HTML(pkgRdDB[[p]],
paste(p, 'html', sep = '.'),
package = pkg,
Links = links,
no_links = is.null(links))
}
setwd(wd) # Get back to the current working directory
}
To use it for your package in development:
static_help("my_package_name")
You will need to re-run this function each time you build the package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With