Make building R packages easier with devtools

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)