
Maintaining example code coverage

Use {covr} to compute example code coverage (i.e. proportion of the source code that is executed when running examples in help pages and vignettes), and to ensure that it is above a certain threshold.
package_coverage(type = c("examples", "vignettes"), commentDonttest = FALSE, commentDontrun = FALSE)
Use a GHA workflow to automate checking that the code coverage via examples never drops below the chosen threshold.
Additional tips
The choice of threshold is subjective and context-sensitive. Once examples and vignettes together reach 100%, as in
statsExpressions, enforcing 100% keeps new code documented. Before that, don’t contort examples to expose every exception just to reach it.The examples not run or tested on CRAN can still be counted for computing code coverage.
Vignettes not included in the package (the ones in
vignettes/subdirectory or.Rbuildignore) will not contribute towards the code coverage. Ditto forREADME. You can adjust the threshold accordingly.You could also choose the threshold on a file basis (
covr::file_coverage()).






















