• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

R/H16-Sep-2020-3,1612,139

build/H03-May-2022-

inst/H16-Sep-2020-500378

man/H06-Mar-2020-898780

src/H16-Sep-2020-3728

tests/H16-Sep-2020-3,0592,450

vignettes/H16-Sep-2020-271203

DESCRIPTIONH A D16-Sep-20203.4 KiB8584

MD5H A D16-Sep-202011.6 KiB185184

NAMESPACEH A D16-Sep-20201.1 KiB4644

NEWS.mdH A D11-Sep-20207.5 KiB212141

README.mdH A D06-Mar-20207 KiB224164

README.md

1# covr <img src="man/figures/logo.png" align="right" />
2
3<!-- badges: start -->
4[![R build status](https://github.com/r-lib/covr/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/covr/actions)
5[![Codecov test coverage](https://codecov.io/gh/r-lib/covr/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/covr?branch=master)
6[![CRAN version](http://www.r-pkg.org/badges/version/covr)](https://cran.r-project.org/package=covr)
7<!-- badges: end -->
8
9Track test coverage for your R package and view reports locally or (optionally)
10upload the results to [codecov](https://codecov.io/) or [coveralls](https://coveralls.io/).
11
12# Installation #
13
14```r
15install.packages("covr")
16
17# For devel version
18devtools::install_github("r-lib/covr")
19```
20
21The easiest way to setup covr on [Travis-CI](https://travis-ci.org)
22is with [usethis](https://github.com/r-lib/usethis).
23
24```r
25usethis::use_coverage()
26```
27
28# Usage #
29
30For local development a coverage report can be used to inspect coverage for
31each line in your package. *Note* requires the
32[DT](https://github.com/rstudio/DT) package to be installed.
33
34```r
35library(covr)
36
37# If run with no arguments implicitly calls `package_coverage()`
38report()
39```
40
41covr also defines an [RStudio Addin](https://rstudio.github.io/rstudioaddins/),
42which runs `report()` on the active project. This can be used via the Addin
43menu or by binding the action to a
44[shortcut](https://rstudio.github.io/rstudioaddins/#keyboard-shorcuts), e.g.
45*Ctrl-Shift-C*.
46
47## Interactively ##
48```r
49# If run with the working directory within the package source.
50package_coverage()
51
52# or a package in another directory
53cov <- package_coverage("/dir/lintr")
54
55# view results as a data.frame
56as.data.frame(cov)
57
58# zero_coverage() shows only uncovered lines.
59# If run within RStudio, `zero_coverage()` will open a marker pane with the
60# uncovered lines.
61zero_coverage(cov)
62```
63
64# Automated reports
65
66## Codecov ##
67If you are already using [Travis-CI](https://travis-ci.org) add the
68following to your project's `.travis.yml` to track your coverage results
69over time with [Codecov](https://codecov.io).
70
71```yml
72after_success:
73  - Rscript -e 'covr::codecov()'
74```
75
76If you are using [Appveyor CI](http://ci.appveyor.com)  then you can add the
77lines below to your project's `appveyor.yml`:
78
79```yml
80on_success:
81  - Rscript -e "covr::codecov()"
82```
83
84You also need to install covr, either by adding it to the `Suggests:` field of
85your package's `DESCRIPTION` file or also to `Remotes: r-lib/covr` if you want
86to install the development version.
87
88To use other CI services or if you want to upload a coverage report locally you
89can set environment variable `CODECOV_TOKEN` to the token generated on
90the settings page of <https://codecov.io>.
91
92## Coveralls ##
93
94Alternatively you can upload your results to [Coveralls](https://coveralls.io/)
95using `covr::coveralls()`.
96
97```yml
98after_success:
99  - Rscript -e 'covr::coveralls()'
100```
101
102For CI systems not supported by coveralls you need to set the `COVERALLS_TOKEN`
103environment variable. It is wise to use a [Secure Variable](http://docs.travis-ci.com/user/environment-variables/#Secure-Variables)
104so that it is not revealed publicly.
105
106Also you will need to turn on coveralls for your project at <https://coveralls.io/repos>.
107
108# Exclusions #
109
110`covr` supports a few of different ways of excluding some or all of a file.
111
112## .covrignore file ##
113
114A `.covrignore` file located in your package's root directory can be used to
115exclude files or directories.
116
117The lines in the `.covrignore` file are interpreted as a list of file globs to
118ignore. It uses the globbing rules in `Sys.glob()`. Any directories listed will
119ignore all the files in the directory.
120
121Alternative locations for the file can be set by the environment variable
122`COVR_COVRIGNORE` or the R option `covr.covrignore`.
123
124The `.covrignore` file should be added to your `.RBuildignore` file unless you
125want to distribute it with your package. If so it can be added to
126`inst/.covrignore` instead.
127
128
129## Function Exclusions ##
130The `function_exclusions` argument to `package_coverage()` can be used to
131exclude functions by name. This argument takes a vector of regular expressions
132matching functions to exclude.
133
134```r
135# exclude print functions
136package_coverage(function_exclusions = "print\\.")
137
138# exclude `.onLoad` function
139package_coverage(function_exclusions = "\\.onLoad")
140```
141
142## Line Exclusions ##
143The `line_exclusions` argument to `package_coverage()` can be used to exclude some or
144all of a file.  This argument takes a list of filenames or named ranges to
145exclude.
146
147```r
148# exclude whole file of R/test.R
149package_coverage(line_exclusions = "R/test.R")
150
151# exclude lines 1 to 10 and 15 from R/test.R
152package_coverage(line_exclusions = list("R/test.R" = c(1:10, 15)))
153
154# exclude lines 1 to 10 from R/test.R, all of R/test2.R
155package_coverage(line_exclusions = list("R/test.R" = c(1, 10), "R/test2.R"))
156```
157
158## Exclusion Comments ##
159
160In addition you can exclude lines from the coverage by putting special comments
161in your source code.
162
163This can be done per line.
164```r
165f1 <- function(x) {
166  x + 1 # nocov
167}
168```
169
170Or by specifying a range with a start and end.
171```r
172f2 <- function(x) { # nocov start
173  x + 2
174} # nocov end
175```
176
177The patterns used can be specified by setting the global options
178`covr.exclude_pattern`, `covr.exclude_start`, `covr.exclude_end`.
179
180NB: The same pattern applies to exclusions in the `src` folder, so skipped lines in, e.g., C code (where comments can start with `//`) should look like `// # nocov`.
181
182# FAQ #
183## Will covr work with testthat, RUnit, etc... ##
184Covr should be compatible with any testing package, it uses
185`tools::testInstalledPackage()` to run your packages tests.
186
187## Will covr work with alternative compilers such as ICC ##
188Covr now supports Intel's `icc` compiler, thanks to work contributed by Qin
189Wang at Oracle.
190
191Covr is known to work with clang versions `3.5+` and gcc version `4.2+`.
192
193If the appropriate gcov version is not on your path you can set the appropriate
194location with the `covr.gcov` options. If you set this path to "" it will turn
195_off_ coverage of compiled code.
196```r
197options(covr.gcov = "path/to/gcov")
198```
199
200## How does covr work? ##
201`covr` tracks test coverage by modifying a package's code to add tracking calls
202to each call.
203
204The vignette
205[vignettes/how_it_works.Rmd](https://github.com/r-lib/covr/blob/master/vignettes/how_it_works.Rmd)
206contains a detailed explanation of the technique and the rationale behind it.
207
208You can view the vignette from within `R` using
209
210```r
211vignette("how_it_works", package = "covr")
212```
213
214## Why can't covr run during R CMD check ##
215Because covr modifies the package code it is possible there are unknown edge
216cases where that modification affects the output. In addition when tracking
217coverage for compiled code covr compiles the package without optimization,
218which _can_ modify behavior (usually due to package bugs which are masked with
219higher optimization levels).
220
221# Alternative Coverage Tools #
222- <https://github.com/MangoTheCat/testCoverage> (no longer supported)
223- [**R-coverage**](https://web.archive.org/web/20160611114452/http://r2d2.quartzbio.com/posts/r-coverage-docker.html) (no longer supported)
224