Patches to add code coverage support in the R interpreter.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Patches to add code coverage support in the R interpreter.


This repository contains patches of the R interpreter source code to add code coverage support. It allows to know which exact lines of source code were exercized/hit/covered while running some piece of code (usually a test suite). The easiest way to test it is using our docker container:


As stated above, you can just use the docker container. To patch it manually:

  1. choose the appropriate patch corresponding to the version of the R interpreter you are going to use.
  2. get the source code of the R version (download and untar)
  3. patch the source code (patch)
  4. configure the source directory (./configure)
  5. compile and install (make; make install)

The project is organized in sudirectories per supported R version, e.g. r302 for R version 3.0.2. The above steps are somewhat automated using a Makefile (you need probably GNU make). For example, to download, untar, patch, configure, make and install R-3.0.2:

git clone
cd r-coverage-patch/r302/
# download, untar and patch
make apply_production_patch 
# install in ./local/
make install 
# Or install in a custom place
make install PREFIX=/whatever/

# run it


I added a condition in the internal C function getSrcref(), that records the line numbers if the code coverage is started (via Rcov_start()). The overhead should be minimal since for a given file, subsequent covered lines will be stored in constant time. I use a hashed env to store the occurrences by file.

I added two entry points in the utils package (Rcov_start() and Rcov_stop())

viewing the main patched file: eval.c

For convenience (Caution: it can be outdated), I included the main patched file in the repo, you can view it here:


(see also

Start the patched R interpreter, then:

pkg  <- download.packages('testthat', '.', repos = "")
untar(pkg[1, 2])

res <- as.list(Rcov_stop())