ramblings on computers, biology, politics, and books

Menu

R package docs + github.io

Ever wish you had a painless way to generate spiffy online documentation for your R package, a la ggplot2? Now you can, using github’s free project site hosting and hadley’s staticdocs package. Here’s how:

Create a new git branch for your project named ‘gh-pages’. Github recognizes this as a special branch name, so an index.html file here will be rendered and visible at http://{your_github_username}.github.io/{project_name}.

Check out ‘gh-pages’ and from that branch, run: staticdocs::build_site(site_path='.')

Watch as staticdocs creates a beautiful web page for your project. Add all the files it generates to git, commit and push it (remember- stay in the gh-pages branch!)

Visit your new site at the URL in #2.

The next step is to keep it updated as you develop your package. To facilitate this, I’ve written a small Makefile:

Now, whenever you make a change to your package that you want reflected in the docs/site, just run make update and it will rebuild the docs, switch to the gh-pages branch, rebuild the site, then push both master and gh-pages branches to Github.