28 Code Coverage: R
28.1 Calculating coverage in R
We use the covr
R package to do this.
Install via R console:
install.packages("covr")
To calculate line coverage and have it show in the viewer pane in RStudio:
::report() covr
Currently covr
does not have the functionality to calculate branch coverage. Thus this is up to you in R to calculate this by hand if you really want to know.
Why has this not been implemented? It has been in an now unsupported package (see here), but its implementation was too complicated for others to understand. Automating the calculation of branch coverage is non-trivial, and this is a perfect demonstration of that.