Produces plain text showing source lines together with their coverage
counts, in a form that is easy to read in a terminal or to paste into a
prompt. By default the missed lines are shown with context surrounding
lines.
annotate_coverage(
x,
lines = NULL,
context = 2,
files = NULL,
max_lines = getOption("covr.annotate_max_lines", 200)
)A character vector of class covr_annotation, with one element per
output line. If there is nothing to show it is "No missed lines.".
A coverage object, e.g. from package_coverage() or
code_coverage().
A data frame with filename and line columns identifying the
lines to show, e.g. the result of zero_coverage() or the lines changed in
a pull request. Other columns are ignored. The default is all missed code
lines in x, and the lines with a missed branch if branch coverage was
measured.
Number of lines to show before and after each line in
lines. Use Inf to show whole files.
Optional character vector of file names (as they appear in the
coverage, e.g. "R/foo.R") to restrict the output to.
The maximum number of source lines to show, 200 by default
(option covr.annotate_max_lines). Whole chunks of lines are added until
the next one would go over the limit, but the first chunk is always shown.
If anything is left out, the last line says how many of the missed or
requested lines in how many files are not shown. Use Inf for no limit.
Each shown line has the line number, a count column and the source. Missed
lines are marked !!0, covered code lines show their hit count, and lines
without coverage data (blank lines, comments, ...) have an empty count.
Non-adjacent chunks are separated by ....
If branch coverage was measured (see covr.branch_coverage), lines with a
branch that was not taken are also shown by default, followed by
<- not taken: and the labels of their missed branches. Only if and
switch() calls that were evaluated count; the others are covered by the
missed lines. Such a line keeps
its count if it was run.
source <- "
f <- function(x) {
if (x) {
'yes'
} else {
'no'
}
}
"
cov <- code_coverage(source, "f(TRUE)")
annotate_coverage(cov)
annotate_coverage(cov, context = Inf)
Run the code above in your browser using DataLab