Learn R Programming

covr (version 4.0.0)

as.data.frame.coverage: Convert a coverage object to a data frame

Description

Convert a coverage object to a data frame

Usage

# S3 method for coverage
as.data.frame(x, row.names = NULL, optional = FALSE, sort = TRUE, ...)

Value

A data frame with one row for each traced expression of R code and each line of compiled code, and the columns:

  • filename: the source file, relative to the root attribute of x (the package directory, for package_coverage()) if there is one.

  • functions: the name of the function containing the expression, or NA for compiled code.

  • first_line, last_line: the lines the expression starts and ends on.

  • first_byte, last_byte: the bytes of those lines the expression starts and ends at.

  • first_column, last_column: the columns the expression starts and ends at. These differ from the bytes when the line contains multibyte characters.

  • first_parsed, last_parsed: the lines as seen by the parser. These differ from first_line and last_line when the source uses #line directives.

  • value: the number of times the expression was executed.

Use tally_coverage() for one row for each line instead.

Arguments

x

a coverage object.

row.names, optional

ignored, for compatibility with base::as.data.frame().

sort

if TRUE (the default), sum the counts of identical expressions and sort the rows by file and position. If FALSE, there is one row for each element of x, in the same order.

...

ignored.

Examples

Run this code
cov <- code_coverage("add <- function(x, y) { x + y }", "add(1, 2)")
as.data.frame(cov)

Run the code above in your browser using DataLab