Day 15: covr

Welcome back for the 15th day of the #packagecalendar, today we will be taking a look at the covr package by Jim Hester. The covr package helps you track test coverage for your R packages.

The package is available from CRAN and can be downloaded with

install.packages("covr")

once you start developing packages you get to a point where you start thinking about implementing unit tests. covr helps you keep track of which parts of the code have had tests done on them. Setting up covr is really easy to set up if you use the usethis package. You simply run the following command and follow the instructions.

usethis::use_coverage()

for local usage you can use the package_coverage() to get a printout of your coverage. For this example, I have cheated a little bit to showcase the result for my prismatic package.

library(covr)
package_coverage()
## prismatic Coverage: 96.65%
## R/color.R: 82.35%
## R/aaa.R: 85.71%
## R/alpha.R: 100.00%
## R/color-blindness.R: 100.00%
## R/greyscale.R: 100.00%
## R/lightness.R: 100.00%
## R/mix.R: 100.00%
## R/negate.R: 100.00%
## R/rotate.R: 100.00%
## R/saturate.R: 100.00%

The report() function will run package_coverage() in the background and will return an interactive table so you can see which lines have been tested.

That is everything I have for today, I look forward to seeing you again tomorrow!