covr (development version)
New
instrument_base_r(),uninstrument_base_r(),base_r_code_coverage()andbase_r_compiled_coverage()measure the coverage of base R itself, both its R code and its C and Fortran code, e.g. while runningmake checkon a build of R from source (#782).base_r_exclusions()lists the functions that are not instrumented by default, as R’s own checks inspect their code.The environment variable that overrides where instrumented packages save their trace files is now
COVR_TRACE_DIR;COVERAGE_DIRis no longer read, as it collides with the variable Bazel sets forbazel coverage(@MichaelChirico, #790).with_coverage(),file_coverage(),function_coverage()and the functions that call them now warn (with classcovr_nested_coverage) when one is called inside another, as the enclosing call’s coverage is incomplete.with_coverage(),file_coverage()and the functions that use them no longer keep the traced environment and copies of its functions in memory after they return (@MichaelChirico, #789).lcov()writes theFNrecord of each function on its first line that has aDArecord, sogenhtmlfrom lcov >= 2.1 no longer fails with “unexpected category UNK” when a function’s first expression is on a line without one, e.g. a doc string (#791).package_coverage()now works when the package’s tests measure the coverage of a package that imports it, e.g. withpackage_coverage(). It failed with “Can’t read coverage trace file”, as an R process that loaded both instrumented packages saved the counts of the last one for both of them. Each instrumented package loaded in a process now has its own counts, so the counts of the package from the processes of the inner run are kept too. Likewise,file_coverage(),code_coverage(),function_coverage(),with_coverage()andenvironment_coverage()no longer reset the coverage of a package whose tests call them (#786).covr no longer calls the non-API C entry points
PRVALUEandRf_findVarInFrame3on R < 4.6, whichR CMD checkreported. R < 4.6 has no API to tell an unevaluated promise from an evaluated one, so on those versions an instrumented package reads all of its lazy-loaded objects when it is loaded, and withcovr.full_traversal = TRUE, functions only reachable through evaluated promises, e.g. arguments of function factories, aren’t traced.package_coverage()no longer fails when pkgbuild, which is only suggested, isn’t installed (#780).Instrumented functions with a braceless
ifbranch before anelse, e.g.x <- if (cond) a else b, now give the same results when they are deparsed and parsed again. Previously theelseattached to covr’s counter (#776).package_coverage()is no longer very slow for packages whose namespace has functions with source references to another package, e.g. theclone()method of R6 classes when R6 was installed with--with-keep.source, or functions created bymemoise::memoise(). covr reparsed the whole package for each conditional in such packages (#768).package_coverage()now works wheninstall_path(which defaults to a directory intempdir()) contains a space. The vignettes andcodeare now run withR --file=rather thanR CMD BATCH, which can’t run a script with a space in its path (#770).-
package_coverage()now works with more characters in the paths of the package,install_pathandtempdir()(#774):- Quotes and backslashes, e.g. a
tempdir()under a user namedO'Brien, in the code it writes to run the vignettes and to load the package. -
%, e.g.%PATH%, on Windows, whereR.exeexpanded environment variables in its arguments. R code is now run withRterm.exe, and%is escaped forR CMD INSTALL. -
=on Windows and*,?and[on Unix in the path of the scripts run for the vignettes andcode, now run with--file=rather than-f. -
',"and%ininstall_pathwhen running examples, which R removed or expanded inR_LIBS_USER. - A relative
install_pathon Unix, for which the tests silently didn’t run.
- Quotes and backslashes, e.g. a
package_coverage()now errors clearly wheninstall_pathcontains a character R can’t have in the path of a library ([, the path separator, or\on Unix), and on Unix when the path of the package or its R files contains"or\, for whichR CMD INSTALLrecords wrong file names, rather than failing later or reporting no coverage (#774).covr no longer deletes files or directories whose names match the paths it cleans up as a glob, e.g. a
lib1next to aninstall_pathoflib[1], and now cleans up those paths themselves (#774).report()andfile_report()no longer run shell commands contained in the path of the report when opening it withbrowseURL()on Unix (#774).lcov()now writes non-ASCII file names in UTF-8, andto_cobertura()no longer fails for them, when the native encoding isn’t UTF-8, e.g. with R 4.1 on Windows (#774).Rust coverage now works when the paths of the profiles contain a comma, or the paths of the libraries it links contain
$or#, and warns rather than silently losing the coverage when the profiles’ directory contains%(#774).With
covr.record_tests = TRUE, tests run from a directory inside the first library, such as<pkg>.Rcheck/testswhenR CMD checkis run with_R_CHECK_SUGGESTS_ONLY_=false, are now recorded separately rather than all as the call that started coverage. On Windows, the calls recorded for tests now start at the test rather than at the top of the call stack, as on other platforms.
covr 4.0.0
CRAN release: 2026-11-16
This is a major release. It changes how coverage is counted in several places, which can lower the coverage covr reports for the same tests; see “Changes to reported coverage” below.
Changes to reported coverage
Reported line coverage may decrease slightly, as it is now computed the same way everywhere, so
print(),percent_coverage(),tally_coverage(),report(),codecov(),coveralls(),cobertura(),sonarqube()andlcov()agree. A line only counts as covered if all its expressions ran, e.g.if (x) a else bon one line whereanever ran is now uncovered inreport(),codecov()andcoveralls(). Lines shared by several functions, such asf <- function() 1; g <- function() 2, are counted once, andprint()andpercent_coverage()only count lines with code, not lines with only punctuation such as}(#620).Expressions in
ifandswitch()branches without braces now get their own counters when the conditional is a function body or nested in another call, such asx <- if (a) b else corfunction(x) if (x) 1 else 2, or in an argument default. Previously the whole expression shared one counter, so a branch that never ran was reported as covered. Coverage of such code may drop, e.g.f <- function(x) if (x) 1 else 2tested only withf(TRUE)drops from 100% to 0% line coverage (#279, #682).Braceless
whileloop bodies are now counted separately from the loop condition, likeifandfor(#732).Lines excluded with
# nocovnow stay excluded when they are part of a larger expression that is not entirely excluded, such as the first and last lines of a function defined inside another function (#594).-
Compiled code coverage counts differently in several cases:
- Lines of C++ templates instantiated more than once in a file are counted once, so
options(covr.gcov_partial = "uncovered")also works on them (#609). - Lines only reached by C++ exceptions, such as a
catchblock that never ran, now count as not covered instead of being left out of the coverage (#609). - Lines of compiled code that gcov reports as only partially executed (e.g.
if (x) f();whenf()never runs) are now included in the coverage. They count as covered, or as not covered withoptions(covr.gcov_partial = "uncovered")(#604). covr now runs gcov with-aso partial lines are also found with llvm-cov, the gcov on macOS, and older versions of gcc (#610).
- Lines of C++ templates instantiated more than once in a file are counted once, so
Breaking changes
covr now requires R 4.1.0 or later, as does httr2, which it uses for uploads (#760).
The option
covr.fix_parallel_mcexitnow takes precedence over the environment variableCOVR_FIX_PARALLEL_MCEXIT, so options always win over theCOVR_*environment variables. The environment variables accepttrue,t,yes,1,false,f,noand0in any case, and warn about other values (#758).covr now looks up gcov when it needs it, with the build tools on the
PATH, rather than setting thecovr.gcovoption when it is loaded, so the gcov of Rtools is found on Windows.getOption("covr.gcov")is nowNULLunless you set it (#758).covr no longer supports code coverage with Intel’s classic
icccompiler, which Intel discontinued in 2024, and thecovr.icov,covr.icov_args,covr.icov_flagsandcovr.icov_profoptions have been removed. Use gcc or clang to measure the coverage of compiled code (#732).S4 methods are now named after their generic and signature, as in their Rd aliases, e.g.
show,MyClass-method, soprint(x, group = "functions"),tally_coverage(by = "function")and the other outputs show which generic each method belongs to. Previously they were named only by their signature, e.g.numeric#character(#417).function_exclusionspatterns that matched the old names need to be updated.azure()is removed. Usecobertura(x, file = "coverage.xml")to write the Cobertura file Azure Pipelines reads (#758).codecov()now throws an error if the upload to codecov.io fails, so CI jobs that upload coverage fail instead of silently succeeding. The error has classcovr_codecov_error. Rate limits (HTTP 429) and Codecov outages (HTTP 5xx) give a warning of classcovr_codecov_warninginstead, so they don’t fail CI (#565).codecov()uses a new upload protocol, andbase_urlis now the upload API rather than"https://codecov.io"; see “CI services and output formats” (#568).codecov()no longer detects Codeship, Semaphore (classic) and Wercker, which have been shut down. Their environment variables are now ignored and the commit, branch and repository come from the local git repository (#732).coveralls()now returns the response of Coveralls invisibly, likecodecov(), and signals an error of classcovr_coveralls_errorfor any response that is not HTTP 200 with a JSON body, with the status and the response in its message (#758).coveralls()now setsservice_nameto"local"rather than"travis-ci"outside a supported CI service, and the git committer fields are now named as Coveralls expects (committer_name,committer_email) (#535).package_coverage()no longer accepts theexclusionsargument, deprecated in favor ofline_exclusions. Useline_exclusionsinstead (#732).package_coverage()no longer has apre_cleanargument. Objects insrc/are always removed before the package is installed, so removepre_cleanfrom calls (#758).sonarqube()now writes file paths relative to the package root (e.g.R/foo.R) instead of prefixing them with the package name, so the report works when the package is the root of the SonarQube project. Use the newpath_prefixargument if the package is in a subdirectory of the project, e.g.path_prefix = "mypkg"restores the previous paths (#636).to_cobertura()andto_sonarqube()are deprecated in favor ofcobertura()andsonarqube(), matching the names ofreport(),codecov()andcoveralls(). Likereport(), the new functions take the coverage asxand the output path asfile. The old names still work, with theircovandfilenamearguments, and warn once per session (#750).to_cobertura()only warns in interactive sessions, so CI workflows that call it, such as the coverage workflow of r-lib/actions, don’t warn (#765).
Performance
Code run to measure coverage is faster. Evaluated expressions are counted in C rather than in R (about 3.5 times less overhead per expression), and instrumented code only checks whether tests are recorded with
covr.record_testsonce, when it is instrumented (#734).Combining the coverage of many R processes is much faster for packages with many traces (@erkurtharun, #643).
Tracing a package is faster, as parse data now keeps text only for terminal tokens (@erkurtharun, #644).
cobertura()andsonarqube()are much faster for large packages, as they write the XML of the lines as text and parse it once, rather than adding each line with xml2 (e.g. 0.3 s rather than 7.5 s, and 0.2 s rather than 3.2 s, for Luminescence). The files they write are unchanged (#755).package_coverage()instruments and byte-compiles a source package once, after installing it, rather than every time a process loads it, so each process that loads it starts faster (e.g. 0.3 s rather than 4.6 s for Luminescence) and doesn’t compile the functions again as it runs them. If that isn’t possible, e.g. the package has functions inR/sysdata.rda, the package is instrumented when it is loaded, as before. Setoptions(covr.install_instrument = FALSE)(or the environment variableCOVR_INSTALL_INSTRUMENT=false) to always do that (#740).package_coverage()is faster and uses much less memory when the code starts many R processes that load the package. Each process now saves only the counts it recorded, which are added to the counters saved when the package was instrumented, rather than all its counters and their source references (a few KB rather than 1 MB per process for languageserver), and the traces of the processes are added up as they are read. Merging the traces of languageserver’s tests, which start about 1,000 processes, now takes 1 s and 144 MB, where it previously ran out of memory at 7 GB (#744).percent_coverage(),tally_coverage(),zero_coverage(),report()and the exclusions inpackage_coverage()are faster for packages with many files, as the package source is now split into files once rather than once per file (#733).report(),report_html()andfile_report_html()are much faster for large packages, as the source table is built as text rather than an htmltools tag per line (e.g. 6 minutes to a few seconds for Luminescence) (#733).tally_coverage(), and sopercent_coverage(),zero_coverage(),coverage_to_list()and the reports, are about 4 times faster for large coverage objects, andprint()about 8 times faster (e.g. 0.16 s rather than 0.7 s, and 0.18 s rather than 1.4 s, for Luminescence). The rows oftally_coverage(by = "line")are now numbered from 1 (#745).
Branch coverage
- New experimental branch coverage of R code. With
options(covr.branch_coverage = TRUE), covr also records which branches of eachif(including anifwithout anelse) andswitch()were taken, in thebranchesattribute of the coverage object.tally_coverage(by = "branch")andpercent_coverage(by = "branch")summarize them, andreport(),file_report(),lcov(),cobertura(),codecov()andcoveralls()include them. Line coverage is unchanged, and without the option the code is instrumented as before, so there is no cost. See?covr.branch_coverage(#279).
Measuring more code
Functions of a package that are sent to other R processes, e.g. parallel workers, are now counted there if the process loads the package (#740).
Functions nested inside lists and environments, such as
fns <- list(a = function(x) x), functions defined insidelocal()and ggproto methods, can now be traced. This is off by default; enable it for a package withConfig/covr/full_traversal: truein its DESCRIPTION, or withoptions(covr.full_traversal = TRUE)(#113).Coverage is now reported for S7 property getters, setters, and validators with S7 > 0.2.2, which stores class callbacks in a shared class reference (@t-kalinowski, #646).
Tracing functions in packages, R6 classes, S7 objects and box modules now skips active bindings, so ones that fail when read (e.g.
makeActiveBinding('x', function() stop('boom'), environment())) don’t break tracing (#732).file_coverage()can now measure the coverage of a package’s compiled code in the current session, e.g.file_coverage("src/foo.c", "tests/foo.R"), which is much faster thanpackage_coverage(). It loads the package withpkgload::load_all(), builds an instrumented copy of it in the session’s temporary directory, and only recompiles the files that changed on later runs.environment_coverage()andwith_coverage()also include the compiled code of packages loaded withpkgload::load_all(), sodevtools::test_coverage_active_file()now works for files insrc/(#605).file_coverage(),environment_coverage()andwith_coverage()also measure the Rust code of packages loaded withpkgload::load_all(), e.g.file_coverage("src/rust/src/lib.rs", "tests/foo.R"), likepackage_coverage()does. cargo only recompiles the crates that changed in the instrumented copy. Without the llvm tools covr warns and skips the Rust code, andoptions(covr.llvm_cov = "")turns this off (#749).file_coverage(),code_coverage(),environment_coverage(),function_coverage()andwith_coverage()now include code run in processes forked by parallel’smclapply(),mcparallel()and related functions, aspackage_coverage()already did. Setoptions(covr.fix_parallel_mcexit = FALSE)to turn this off (#410).package_coverage()now measures the coverage of Rust code, such as the code of packages using extendr or savvy. It’s built with LLVM’s source-based coverage, which needs the llvm tools of the Rust toolchain (rustup component add llvm-tools), or for Rust installed by a Linux distribution, those of the LLVM version rustc uses (e.g.llvm-cov-18). Without them, covr warns and measures everything except the Rust code.options(covr.llvm_cov = "")turns this off (#728).package_coverage()now measures the coverage of installed packages, e.g.package_coverage(system.file(package = "pkg")), so the package source isn’t needed. The package must be installed with--install-testsand--with-keep.source, andpackage_coverage()errors if it wasn’t (#638).New
shiny_app_coverage()measures the coverage of a Shiny app that isn’t part of a package while its tests run, by default withshinytest2::test_app(), including the code run by the app in the R processes that shinytest2 starts. The newvignette("shiny")describes how to measure the coverage of Shiny apps, including tests run with shinytest2 and apps that aren’t in a package (#277).
Reports
The RStudio addin now prints a message when it starts calculating coverage, so there is feedback before the report opens (#404).
file_report()now creates the directory ofout_fileif needed and returns its absolute path, likereport()(#758).file_report()highlights the syntax of the source code again; it failed with JavaScript errors as the report didn’t include jQuery (#708).report()highlights code with highlight.js 11, which supports light and dark themes (#758).report()’s file list is easier to read: the column headers stay on one line,Hits / Lineis renamed toHits/lineand shows one decimal place (or<0.1) with a tooltip explaining it, numbers line up, and a row with the totals follows the files when there are several (#756).report()’s file list only wraps file names after a/in narrow reports, e.g. one embedded withreport_html(), and scrolls horizontally if it doesn’t fit, rather than cutting off the last columns (#763).report()andfile_report()no longer need the DT package, jQuery or Bootstrap, and no longer bundle Bootstrap, whose bundled version had known security vulnerabilities (#639). The file list is now sorted with the least covered files first (#316).report()andfile_report()use a dark theme when the browser prefers one, and have a button to switch between the light and dark themes, which the browser remembers for other reports (#563).report(),file_report()and their_html()versions show branch coverage when it was measured: lines with branches show how many were taken (e.g.1/2, with each branch’s label and count on hover), lines with an untaken branch are shown as partly covered in thepartialcolor ofcovr.report_colors(yellow by default), and the file list has a “Branches” column, with the overall percentage of branches taken in the title. Reports without branch coverage are unchanged (#751).report(),file_report()and the coverage percentages printed in the console can use other colors for covered and missed code, set with the newcovr.report_colorsoption. The newcolorblind_palettehas blue, yellow and vermillion from the Okabe-Ito palette, which are easier to tell apart with color vision deficiency than the default green and red:options(covr.report_colors = covr::colorblind_palette). An optionalpartialelement sets the color for 75% to 90% coverage and for partly covered lines with branch coverage. The coverage bars inreport()now use the same thresholds as the console, so files with exactly 75% or 90% coverage get the higher color (#529, #751).report()now keeps the Files / Source tabs at the top of the page while scrolling, and returning to the file list restores its scroll position (#232).report()now works when the coverage object has no traces; it failed with “invalid argument to unary operator” (#540).New
report_html()andfile_report_html()return the coverage reports ofreport()andfile_report()as HTML that can be included in a larger document, such as an R Markdown or Quarto document. The reports’ styles and scripts only apply to the report, and a report doesn’t replace the document’s highlight.js, so a document can include several reports without changing the rest of the page (#709).
CI services and output formats
covr uses httr2 instead of httr to upload coverage to Codecov and Coveralls (#758).
New
badge()writes an SVG badge with the percent coverage, so a README can show coverage without uploading it to Codecov or Coveralls. The README has an example GitHub Actions workflow that publishes the badge (#634).cobertura()now only lists the lines of a method from the file it is defined in, so methods sharing a name across files, such as theinitialize()methods of R6 classes, don’t list each other’s lines, and Codecov shows the correct line numbers and the same coverage asprint()(#629).codecov()andcoveralls()use the current Drone variablesDRONE_COMMIT_BRANCH,DRONE_COMMIT_SHAandDRONE_BUILD_LINK, and fall back to the old ones (#758).codecov()now uploads with Codecov’s current upload protocol, a request tohttps://ingest.codecov.iofor an upload followed by sending the coverage to the location it returns, instead of the legacy/upload/v2endpoint, which Codecov has deprecated and which doesn’t support organization-level upload tokens. The repository and git service come from the CI service or theoriginremote. Without a token, pull requests from forks on GitHub Actions are uploaded from an unprotected branch (owner:branch), likecodecov/codecov-actiondoes, and on GitHub Actions pull requests use the head commit of the pull request (#568, #464).codecov()now returns the response of Codecov, which includes theurlof the upload (#568).codecov()outside a git repository now gives its “Can’t determine the repository” error, rather than a raw git error (#732).New
coverage_to_markdown()formats coverage as a markdown table, optionally compared against a baseline, for GitHub Actions job summaries or pull request comments (#519).coveralls()uses the environment variableCOVERALLS_REPO_TOKENifCOVERALLS_TOKENis not set, and deletes the temporary file with the coverage it uploaded (#758).coveralls()now detects the CI service, job and pull request on the services thatcodecov()supports, e.g. GitHub Actions, instead of assuming Travis CI. With arepo_token, it also submits the git commit, branch and remote on every service, or from the local git repository outside CI, so the Coveralls badge is updated for the right branch (#535).New
lcov()writes coverage as an LCOV tracefile (lcov.info), forgenhtmland other tools that read the LCOV format (#442, thanks to @MichaelChirico for the initial implementation in #637).sonarqube()now reports the lines of compiled code, and with branch coverage (options(covr.branch_coverage = TRUE)) thebranchesToCoverandcoveredBranchesof each line (#758).
Working with coverage results
Error and warning messages are shorter and follow the tidyverse style guide, starting with a short statement of the problem followed by bulleted details, e.g. for unpaired
# nocov start/# nocov endlines (#710).The error for unpaired
# nocov startand# nocov endcomments now gives the name of the file along with the line numbers of the comments (#409).covr_errorconditions (and thecovr_warnings fromallow_failures) now keep the whole failure output in$outputand its file in$file. The message shows the last 50 lines, bounded bywarning.lengthin characters, andprint()shows the lastnlines, 50 by default. The number of lines can be set withoptions(covr.failure_lines)(#570, #642).New
annotate_coverage()shows the source of the missed lines, or any other lines, as plain text with their execution counts, so coverage can be read without the HTML report, e.g. by coding agents. With branch coverage, lines with a branch that was never taken are shown and marked too. Its output is capped at 200 source lines (max_lines, or thecovr.annotate_max_linesoption), ending with how many lines were left out (#742).c()now combines coverage objects, e.g. from runs of tests in different directories. The counts of traces in several objects are added, and recorded tests are combined as well (#439).New
current_coverage()returns the coverage measured so far in the current process, and can reset the counts, so code run by covr can measure the coverage of parts of a run, such as each test file. Use it rather than reading covr’s internal counters, which no longer show the counts while code runs (#759).print()of coverage objects gainsmissingandnarguments.missing = TRUElists the missed lines of each file or function as ranges such as41-48, 112, and the missed branches if branch coverage was measured; at most 10 ranges and branches are listed for each file or function, which can be changed with thecovr.print_max_rangesoption.nlimits the number of files or functions printed, showing the least covered first. The branch coverage percentage is shown when it was measured (#215, #742).tally_coverage()gainsby = "function", with one row for each function, sozero_coverage(cov, by = "function")lists the functions that were never run.percent_coverage()andprint()also accept it (#245).New
tally_tests()returns a traceability matrix from coverage recorded withoptions(covr.record_tests = TRUE): which tests ran each line of code, with the test file, line andtest_that()description, so you can find the tests to rerun after changing some lines (#361).value()now works on coverage objects of R code, not only compiled code. The structure of coverage objects is now documented in?coverage, andas.data.frame()on a coverage object in?as.data.frame.coverage(#564).
Running coverage
Trace files are now written atomically, and a failure to save or read one is reported as a
covr_error(acovr_warningwithallow_failures = TRUE) naming the file, rather than a crypticreadRDS()error (#509).file_coverage()gains arunnerargument to choose how test files are run.runner = testthat::test_fileruns them with testthat’s test runner, soexpect_snapshot()and other features that need it work (#501).package_coverage()gains anallow_failuresargument (defaultgetOption("covr.allow_failures", FALSE)). WhenTRUE, failing tests, vignettes, examples orcodeproduce a warning instead of an error and coverage is still returned, e.g. socovr::report()can be viewed after a long test run with a failure (#533).package_coverage()gains ashow_code_outputargument. IfTRUE, the output ofcodeis shown on the console while it runs, e.g. to follow it in the logs of a CI job, rather than only being shown whencodefails (@gergness, #558).package_coverage()now keepsinstall_pathwhen coverage fails, or when failures are reported as warnings withallow_failures = TRUE, so the output files they refer to can be inspected (@hadley, #554, #615).package_coverage()now acceptsoutDirin...to save the test and example output to a directory of your choice, instead of failing with “formal argument”outDir” matched by multiple actual arguments” (#518).package_coverage()now warns when an R process started by the tests, such as a Shiny app, callr session or future worker, loaded the package but did not save its coverage because it was killed or was still running when the tests finished. That coverage used to be silently missing, so the results could vary from run to run (#438).package_coverage()now works in renv projects when the package imports renv, or a package that embeds it such as vetiver, as covr no longer passes its library paths as site libraries, which renv removes (#560).package_coverage()now keeps the coverage measured so far, and doesn’t fail with “‘from’ must be a finite number”, whencodeloads the package again withpkgload::load_all(), e.g. viadevtools::test()(#641).package_coverage(combine_types = FALSE)now works when its arguments are local variables of the calling function (#732).New
with_coverage()measures the coverage of arbitrary code, such astestthat::test_file(), run against an environment like a package namespace loaded withpkgload::load_all(). This allows tools such asdevtools::test_coverage_active_file()to use testthat’s own runner instead of recreating it, so setup files and fixtures found withtestthat::test_path()work as they do intestthat::test_file()(related to #543, #551).
Compiled code
Compiled code in packages that set
CXX_STD = CXX23is now instrumented (#758).Compiled code coverage only reads the gcov reports written by each gcov run, so stale
.gcovfiles insrc/are left alone (#758).Source files are now matched against the package directory and
covr.gcov_additional_pathsby whole path components, not by a prefix anywhere in the path. Native files incovr.gcov_additional_pathsare now kept whencovr.filter_non_packageis set (#758).Compiled code coverage now reads gcov’s structured JSON output (
gcov --json-format) when gcov supports it (gcc >= 9), instead of parsing its text output with regular expressions. covr still parses the text output of llvm-cov, the gcov on macOS, and older gcc, and falls back to it for any file whose JSON output is missing or can’t be read (#609).options(covr.gcov = "")once again turns off coverage of compiled code, as documented, instead of failing with “gcov not found” (#516).When gcov fails, the error from
package_coverage()now includes gcov’s output, e.g. the.gcnoversion mismatch reported when the package was compiled with a different version of gcc than the gcov used (#537).package_coverage()now also excludes theinst/include/<pkg>_RcppExports.hheader that Rcpp generates for// [[Rcpp::interfaces(cpp)]], like the other files generated by Rcpp and cpp11. These generated files are now also excluded withrelative_path = FALSEor a customrelative_path(#531).
Bug fixes
Coverage of a file whose name starts with
testsis no longer mistaken for recorded tests (#758).relative_path = "/"and other filesystem roots, such asC:/, are no longer changed when trailing slashes are removed (#758).The
COVR_COVRIGNOREenvironment variable is now read each time it is needed, rather than only when covr is loaded (#758).Tracing a
switch()call with fall-through cases (a = ,) whose subject is piped in with the base pipe (x |> switch(...)) no longer errors with “argument is missing, with no default” (#630).Tracing a
switch()call with a trailing comma no longer warns, which was an error underoptions(warn = 2)(#483).Measuring the coverage of httr and its dependencies, such as R6, no longer fails with a cyclic namespace dependency (#623).
Replacing traced functions in place no longer risks a generational garbage-collection bug, and doesn’t permanently keep their bodies or environments (#640).
-
Two fixes for
options(covr.record_tests = TRUE)(#627):- Objects used in tests can now be garbage collected. covr kept the environment of the last test call, which made tests that check that objects are finalized fail, e.g. in websocket.
- Tests without srcrefs, such as the scripts in
tests/that don’t use testthat, are now recorded once and counted when they run again, e.g. in a loop, like tests with srcrefs. Each run was recorded as a new test, and finding the test got slower with every run, so the coverage of bitops never finished.
With
options(covr.record_tests = TRUE), tests that call the package through code with source references, e.g. testthat expectations when rlang was installed withR_KEEP_PKG_SOURCE=yes, are no longer all recorded as a single test named after that code (#723).With
options(covr.record_tests = TRUE), functions in the recorded test calls, such as those of R6 active bindings, no longer keep their environment. Saving the coverage of tests that used an active binding of an R6 object holding data read with arrow crashed R (#573).With
options(covr.record_tests = TRUE), merging coverage now correctly renumbers the test indices of traces that are absent from the first coverage object (#643).Fixed two rare crashes and an error with
options(covr.record_tests = TRUE)(@maksymiuks, #631).package_coverage()no longer crashes R when a package stores data read with arrow in an environment of its namespace, e.g. in a fastmap. The coverage saved by each R process included the contents of the package’s environments, which are no longer saved, so it is also smaller (#602).package_coverage()no longer reports 0% coverage for packages whose last file inR/is empty (#522).package_coverage()no longer reports spurious uncovered lines for bracelessif,forandswitchconditions when some of the R processes that load the package run withoptions(keep.parse.data = FALSE)(#732).print()of a coverage object no longer fails or prints the wrong text for file or function names that contain braces (#758).with_coverage(),function_coverage()and the other functions that measure coverage now restore the functions wrapped byVectorize()andmemoise::memoise(), so later measurements of them are no longer lost. Functions are only treated asVectorize()wrappers if they have the wrapper’s own bindings (#758).zero_coverage()no longer errors in RStudio when rstudioapi isn’t installed (#732).
covr 3.6.5
CRAN release: 2025-11-09
New Features and improvements
Added support for
klmr/boxmodules. This works best withfile_coverage(). (@radbasa, #491)Performance improvement for compiled code with a lot of compilation units (@krlmlr, #611)
Fix R CMD check NOTE for upcoming R 4.6: non-API calls to SET_BODY, SET_CLOENV, SET_FORMALS (@t-kalinowski, #587)
Fixes and minor improvements
Messages are now displayed using cli instead of crayon (@olivroy, #591).
covr now uses
testthat::with_mocked_bindings()for its internal testing (@olivroy, #595).Fix a bug preventing
package_coverage()from running tests wheninstall_pathis set to a relative path (@gergness, #517, #548).Fixed a performance regression and an error triggered by a change in R 4.4.0. (@kyleam, #588)
Fixed an issue where attempting to generate code coverage on an already-loaded package could fail on Windows. (@kevinushey, #574)
Prevent
covr.record_testsoption from logging duplicate tests when the same line of testing code is hit repeatedly, as in a loop. (@dgkf, #528)Normalize
install_pathpath before creating directory to prevent failures when running covr in a subprocess using a path with Windows\\path separators. (@maksymiuks, #592)
covr 3.6.3
CRAN release: 2023-10-10
Updates to internal usage of
is.atomic()to work with upcoming R release (@mmaechler , #542)package_coverage()now works correctly with ignore files when it is not run in the package root directory (@mpadge, #538)
covr 3.6.2
CRAN release: 2023-03-25
- Fix S3 generic/method signature consistency and skip an R6 test on R-devel, for CRAN checks (#534).
covr 3.6.1
CRAN release: 2022-08-26
to_cobertura()is now explicit about the doctype of the resulting XML. It also sets a source path if recorded. (@mmyrte, #524)The internal generic
merge_coverage()now correctly registers the S3 methods.The internal test for recording large calls no longer assumes R is on the system PATH.
covr 3.6.0
CRAN release: 2022-08-24
Added
covr.record_testsoption. WhenTRUE, this enables the recording of the trace of the tests being executed and adds an itemization of which tests result in the execution of each trace. For more details see?covr.record_tests(@dgkf, #463, #485, #503)as.data.frame()now returns an 0 row data frame when there are no functions in a package (#427)codecov()is now more robust whencoverageis not the output frompackage_coverage()andtokenis not provided (#456)package_coverage(code = )now accepts character vectors of length greater than 1 (@bastistician, #481)package_coverage()now handles packages with install or render time examples (#488)package_coverage()now sets the environment variableR_TESTSto the tests-startup.R file like R CMD check does (#420)report()now provides a more detailed error message if theDTandhtmltoolsdependencies are not installed (#500).Fix
parse_gcovbug when package is stored in directory with regex special characters, see #459Error/warning thrown for, respectively, missing gcov or empty parsed gcov output (@stephematician, #448)
Support Google Cloud Build uploading reports to Codecov.io (@MarkEdmondson1234 #469)
covr is now licensed as MIT (#454)
covr 3.5.1
CRAN release: 2020-09-16
codecov()andcoveralls()now retry failed requests before raising an error (#428, @jameslamb)
covr 3.5.0
CRAN release: 2020-03-06
codecov()now supports GitHub Actions for public repositories without having to specify a token.New
to_sonarqube()function added to support SonarQube generic XML format (@nibant, @Delfic, #413).
covr 3.4.0
CRAN release: 2019-11-26
codecov()now supports GitHub Actions.New
in_covr()function added to return true if code is being run by covr (#407).file_coverage(),environment_coverage()andfunction_coverage()now setR_COVR=true, to be consistent withpackage_coverage()(#407)
covr 3.3.1
CRAN release: 2019-08-23
- Fix inadvertent regression in return visibility when functions are covered. covr versions prior to 3.3.0 surrounded each statement in
{blocks. covr 3.3.0 switched to using({, but this caused an inadvertent regression, as(will make the result visible it is the last expression in a function. Usingif (TRUE) {restores the previous behavior. (#391, #392)
covr 3.3.0
CRAN release: 2019-08-06
New Features
New
azure()function added to make it easy to use covr on Azure Pipelines (#370)Work around issues related to the new curly curly syntax in rlang (#379, #377, rlang#813)
Compiled code coverage has been improved, in particular C++ templates now contain the merged coverage of all template instances, even if the instances were defined in separate compilation units. (#390)
Bugfixes and minor improvements
codecovnow lookscodecov.ymlfor token ifCODECOV_TOKENenvvar is not set (@MishaCivey #349).per_line()now does not track lines with only punctuation such as}or{(#387)tally_coverage()now includes compiled code, like it did previously (#384)Define the necessary coverage flags for C++14, C++17 and C++20 (#369).
to_cobertura()now works with Cobertura coverage-04.dtd (@samssann, #337).R6 class generators prefixed with
.are now included in coverage results (@jameslamb, #356).package_coverage()gains optionpre_clean, set toFALSEto disable cleaning of existing objects before runningpackage_coverage()(@jpritikin, #375)
