5
votes

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?

2
What format is the vignette expected to be rendered to for inclusion in the package? - Gavin Simpson
The vignette would be preferably in pdf format as plots take slightly less space but both are good. I know how to export vignettes to both pdf and html formats. My question is more about exporting the function documentation to html files. - Paul Rougieux

2 Answers

4
votes

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

2
votes

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.