R/pkg_ref_cache_covr_coverage.R

Defines functions pkg_ref_cache.covr_coverage.pkg_source pkg_ref_cache.covr_coverage

Documented in pkg_ref_cache.covr_coverage.pkg_source

#' Retrieve output of covr::package_coverage
#'
#' @inheritParams pkg_ref_cache
#' @family package reference cache
#' @return a \code{pkg_ref} object
#' @keywords internal
#' @noRd
pkg_ref_cache.covr_coverage <- function(x, ...) {
  UseMethod("pkg_ref_cache.covr_coverage")
}


#' Retrieve output of covr::package_coverage
#'
#' @importFrom tools testInstalledPackage
#' @importFrom covr package_coverage
#' @return a \code{pkg_ref} object
#' @keywords internal
pkg_ref_cache.covr_coverage.pkg_source <- function(x, ...) {
  # use custom 'code' to avoid triggering errors upon test failure.
  # practically identical to covr::package_coverage with the exclusion of
  # `if (result != 0L) show_failures(out_dir)`
  expr <- bquote(tools::testInstalledPackage(.(x$name), types = 'tests'))
  cnsl <- capture_expr_output({
    res <- covr::package_coverage(
      path = x$path,
      type = "none",
      code = deparse(expr))
  })

  res
}

Try the riskmetric package in your browser

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

riskmetric documentation built on Sept. 1, 2023, 1:06 a.m.