Testing a package

When we build a package, it is very important to test it. Packages can get very complex structures and this creates a high potential for bugs. The most basic way to test your package is to build and load it again and again and test all its functions simply by using them. But this only works up to a certain package size. If our package gets too big, we cannot test every single function after every change we made to the package.

The better way to test our packages when they reach a certain size is the testthat package, created by Hadley Wickham, who also created the devtools package. This package is available on CRAN, so we can simply install it with the install.packages() function.

Using testthat in a package

Before we can use

Get Mastering RStudio – Develop, Communicate, and Collaborate with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.