Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export R package documentation to a web page

Tags:

package

r

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?

like image 593
Paul Rougieux Avatar asked Jun 17 '15 16:06

Paul Rougieux


People also ask

How do I write R package documents?

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.

What is .RD File in R?

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.

What is Roxygen?

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")

How do you add Roxygen?

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.


2 Answers

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

like image 199
Gavin Simpson Avatar answered Oct 07 '22 13:10

Gavin Simpson


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.

like image 44
Paul Rougieux Avatar answered Oct 07 '22 15:10

Paul Rougieux