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. Chasing after 100% example code coverage is futile (since this would require exposing every exception in the examples).
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()
).