The main aim of the rcov R package is to provide a tool for measuring different types of code coverage for R code.
Development of package just started recently and is far away from CRAN release yet.
It can be installed easily with the nifty function of the devtools package from CRAN:
library(devtools)
install_github('allr/rcov')Or download the sources and build manually. If you're running R on Windows, you need to install Rtools.
Function is the smallest building block for code coverage measure. To start monitoring function for coverage information, it needs to be decorated first by MonitorCoverage. To see the coverage information call ReportCoverageInfo.
f <- function(x) {
if (x %% 2 == 0){
x <- x + 20
} else {
x <- 10
}
x
}
MonitorCoverage(f)
f(1)
ReportCoverageInfo()
f(2)
ReportCoverageInfo()ReportCoveragePercentage reports mean of coverage percentage accross all function that coverage is being monitored for.
ReportMissingStatements returns a list of statements that were not executed for function whose coverage is being monitored.
MonitorCoverage(agrep)
MonitorCoverage(abbreviate)
examples(agrep)
# get mean of coverage percentage
ReportCoveragePercentage()
# list statements that were not covered
ReportMissingStatements()There are some other projects for R code coverage that I am aware of: