Setting the stage

Slides available on speakerdeck

UBC STAT545 2015 Writing your first R package from Jennifer Bryan

Prepare your system for package development

System prep and testing

Although we’ll build a very simple package, we’re still going to use the most modern and powerful tools for R package development. In theory, this could eventually involve compiling C/C++ code, which means you need what’s called a build environment. Follow the link above for help preparing your system.

Hands-on activity

In class example that that shows how to

In 2016 and 2015, we built the foofactors package, to make the care and feeding of factors less aggravating.


Writing R Extensions, the One True Official Document on creating R packages.

R packages from Hadley Wickham. The above lessons follow it and the devtools package workflow quite faithfully. devtools on CRAN, on GitHub.

Hilary Parker’s blog post on the epiphany of writing her first R package

Karl Broman’s guide to writing an R package

Karl Broman covers package development in his course Tools for Reproducible Research

Jeff Leek’s guide to writing R packages

Some blog posts accompanying devtools releases highlight useful helper functions for package developers:

Building and Maintaining R Packages with devtools and roxygen2, blog post by Jacob Montgomery and Ryan T. Moore

Writing Package Vignettes, slides for a November 2013 talk by Duncan Murdoch

Roxygen vignette on Generating Rd files

testthat: Get Started with Testing, an article written by Hadley Wickham for The R Journal, Vol. 3/1, June 2011, pp. 5-10. This may no longer be correct in every last detail, due to evolution of testthat, but it still makes an excellent, readable introduction to unit testing in R (packages).

How R Searches and Finds Stuff is a fairly technical blog post for understanding the R search path, but also gives some great explanations on some differences between Imports vs Depends and why Imports is safer.