Prepare an existing coverage environment for use with coverage workflows that evaluate tests in an isolated environment, typically one created with `new.env(parent = baseenv())`.
setup_covr_env(
pkg_source_path,
pkg_name,
test_path = "tests/testthat",
cov_env
)A named list with components:
The populated coverage environment.
Character vector of dataset objects loaded into `cov_env` from the target package, `datasets`, and optionally `nycflights13`.
Character vector of datasets loaded from the `datasets` package.
Character vector of exported objects copied from Base R packages other than `base` and `datasets`.
Resolved project root path.
Character vector of object names present in `cov_env` before setup.
Character vector of helper files successfully sourced into `cov_env`.
Character scalar. Path to the source package root.
Character scalar. Package name.
Character scalar. Path to the test directory. Defaults to `"tests/testthat"`.
Environment. A pre-existing coverage environment, usually created by an initializer such as `initialise_covr_env()`.
The setup process:
- loads helper files from `tests/testthat`, - loads package namespace objects into `cov_env`, - resolves the project root, - loads package datasets into `cov_env`, - loads Base R datasets and exports into `cov_env`, - optionally loads `nycflights13` datasets if available, - loads dependencies into `cov_env`, and - unloads the package namespace afterward to reduce conflicts.
This function does **not** create `cov_env`; it expects an existing environment to be supplied.
This function is designed for workflows where `cov_env` is deliberately isolated (for example with `parent = baseenv()`). In such cases, objects from packages like `stats` and `datasets` are not automatically visible, so they are explicitly loaded into `cov_env`.
The package `nycflights13` is treated as optional: if it is installed, its datasets are loaded into `cov_env`; otherwise it is silently skipped.