Make building R packages easier with devtools

February 6, 2013

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

If you're writing any significant amount of R code, you might want to start think about bundling it up into packages. An R package combines functions, data, documentation and unit tests, and is a convenient and reliable system to manage and version collections of R content that could otherwise become unwieldy. And if you want to share your code with colleagues or even the entire world via github or CRAN, an R package is the best way to do it.

The canonical documentation for building an R package is the Writing R Extensions Guide that comes with the R distribution. Following all of these instructions by hand can be a little complicated, but fortunately Hadley Wickham and his colleagues at RStudio have created the devtools package to make the process simpler.

The devtools package makes it much easier to create a package following the structure defined in the Extensions Guide. It also makes it easier to test your package, using the unit tests you've been creating. (You have been writing unit tests, right? Including unit tests in a package is an excellent idea: not only does it make your package more reliable in the long run, it also simplifies the development process in surprising ways. If you're not writing unit tests, definitely give it a go.)

Another good practice is to manage your package code in a source-code control system. (Packages have their own version numbers, which you can use to keep track of updates to your code.) If you're using github to manage your code, you can also install your package directly from github with the install_github command (this is also a handy way to share your package with others). And if you want to share your package to the entire world, devtools can also test if your package is ready to submit to CRAN (though be sure to read the CRAN submission guidelines first).

You can find more information about devtools at the package homepage linked below.

RStudio Projects: devtools

To leave a comment for the author, please follow the link and comment on their blog: Revolutions. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training


CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)