R/prep_covr.R

Defines functions covr

#' @include lists.R prep_utils.R
#' @importFrom covr package_coverage zero_coverage percent_coverage
#' @importFrom withr with_options

PREPS$covr <- function(state, path = state$path, quiet) {
  state <- run_prep_step(state, "covr", function(path, quiet) {
    list(coverage = package_coverage(path, quiet = quiet))
  }, path = path, quiet = quiet, silent = quiet)

  if (!inherits(state$covr, "try-error")) {
    state$covr$zero <- with_options(
      list(covr.rstudio_source_markers = FALSE),
      zero_coverage(state$covr$coverage)
    )
    state$covr$pct_by_line <- percent_coverage(state$covr$coverage, by = "line")
    state$covr$pct_by_expr <- percent_coverage(
      state$covr$coverage, by = "expression"
    )
  }

  state
}

Try the goodpractice package in your browser

Any scripts or data that you put into this service are public.

goodpractice documentation built on June 5, 2026, 5:06 p.m.