| Title: | Assessing Package Test Reliability and Quality |
|---|---|
| Description: | A reliable and validated tool that calculates unit test coverage for R packages with standard testing frameworks and non-standard testing frameworks. |
| Authors: | Edward Gillian [cre, aut] (ORCID: <https://orcid.org/0000-0003-2732-5107>), Hugo Bottois [aut] (ORCID: <https://orcid.org/0000-0003-4674-0875>), Paulin Charliquart [aut], Andre Couturier [aut], Sanofi [cph, fnd] |
| Maintainer: | Edward Gillian <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 2.1.2 |
| Built: | 2026-06-10 11:49:36 UTC |
| Source: | https://github.com/cran/test.assessr |
Helper to extract "R/<file>" from any path by taking the last two components
extract_short_path(long_file_name)extract_short_path(long_file_name)
long_file_name |
A string containing the full file path (supports '/' or '\') |
A character string composed of the last two path components, e.g., "R/add.R"
Generates an HTML report for the package test assessment results using rmarkdown.
generate_test_report(test_results, output_dir = NULL)generate_test_report(test_results, output_dir = NULL)
test_results |
List containing the results from get_package_coverage function. |
output_dir |
(required) Character string path to an existing directory where the report will be saved. |
Path to the generated HTML report.
## Not run: test_results <- get_package_coverage() # Always provide a directory; tempdir() is convenient in examples. generate_test_report(test_results, output_dir = tempdir()) ## End(Not run)## Not run: test_results <- get_package_coverage() # Always provide a directory; tempdir() is convenient in examples. generate_test_report(test_results, output_dir = tempdir()) ## End(Not run)
simplified input to assess package for test coverage
get_package_coverage(path = NULL, package_installed = NULL)get_package_coverage(path = NULL, package_installed = NULL)
path |
(optional) path to locally stored package source code. If
|
package_installed |
(optional) logical flag that controls local
package installation. If |
An object of class "coverage" as produced by
test.assessr::run_covr_modes().
This object is a structured list containing detailed test coverage
information, including:
File-level coverage: percentage of lines covered in each file.
Line-by-line coverage: number of executions for each line.
Overall coverage: aggregated coverage across the package.
Metadata: source file paths, expressions, and summary stats.
The resulting object can be printed, summarized, or passed to
test.assessr::generate_test_report() to produce a human-readable test
coverage report.
Returns NULL if the package cannot be installed, if
install_list$pkg_source_path is missing/empty, or if the specified
path does not exist.
# Example STF package included in test.assessr pkg_source_path <- system.file( "test-data", "test.package.0001_0.1.0.tar.gz", package = "test.assessr" ) # Run get_package_coverage pkg_test_coverage <- get_package_coverage(pkg_source_path)# Example STF package included in test.assessr pkg_source_path <- system.file( "test-data", "test.package.0001_0.1.0.tar.gz", package = "test.assessr" ) # Run get_package_coverage pkg_test_coverage <- get_package_coverage(pkg_source_path)
get package name for display
get_pkg_name(input_string)get_pkg_name(input_string)
input_string |
- string containing package name |
pkg_disp - package name for display
pkg_source_path <- "/home/user/R/test.package.0001_0.1.0.tar.gz" pkg_disp_1 <- get_pkg_name(pkg_source_path) print(pkg_disp_1) pkg <- "TxDb.Dmelanogaster.UCSC.dm3.ensGene_3.2.2.tar.gz" pkg_disp_2 <- get_pkg_name(pkg) print(pkg_disp_2)pkg_source_path <- "/home/user/R/test.package.0001_0.1.0.tar.gz" pkg_disp_1 <- get_pkg_name(pkg_source_path) print(pkg_disp_1) pkg <- "TxDb.Dmelanogaster.UCSC.dm3.ensGene_3.2.2.tar.gz" pkg_disp_2 <- get_pkg_name(pkg) print(pkg_disp_2)
Attempts to install an R package from a local source directory using
remotes::install_local(). The function reports on whether installation
succeeded, whether the package was already installed, or whether the provided
source path does not exist.
install_package_local(pkg_source_path)install_package_local(pkg_source_path)
pkg_source_path |
Character string. Path to the local package source directory (e.g., an unpacked package or extracted tarball path). |
The display name of the package is derived from the input path using
get_pkg_name().
A logical value indicating whether the package is installed after running the function.
The returned object is always of class logical:
TRUE — The package is already installed or was successfully installed.
FALSE — Installation failed or the path does not exist.
TRUE does not necessarily imply that the installation occurred during
this function call—it may also mean the package was already installed.
FALSE indicates a failure to install or an invalid path. All diagnostic
messages are printed via message() for user visibility.
## Not run: results <- install_package_local("pkg_source_path") print(results) ## End(Not run)## Not run: results <- install_package_local("pkg_source_path") print(results) ## End(Not run)
This function executes code coverage analysis for a package using the 'covr' framework. It is typically used after a package has been installed locally and test files are available. The function runs coverage in an isolated process (using 'callr') and returns a structured summary of overall and file‑level coverage.
run_coverage(pkg_source_path, timeout = Inf)run_coverage(pkg_source_path, timeout = Inf)
pkg_source_path |
Character. Path to the installed package directory from which coverage should be computed. |
timeout |
Numeric. Timeout (in seconds) passed to
|
The function invokes covr’s coverage evaluation in a clean R session and extracts both:
total coverage: percentage of lines covered across the package, and
function/file‑level coverage: coverage data for individual files.
It is used internally by higher‑level functions such as
run_covr_modes() and skip‑aware coverage wrappers in the Standard
Testing Framework (STF).
A named list containing:
Numeric. Aggregated coverage percentage for the package.
A list containing file‑level or function‑level coverage results as returned by 'covr'. This includes per‑file coverage, errors, and diagnostic notes if present.
Returns NULL if coverage could not be computed.
# Save and adjust CRAN mirror for reproducibility r <- getOption("repos") old <- options(repos = r) r["CRAN"] <- "http://cran.us.r-project.org" options(repos = r) # Example package from test.assessr dp <- system.file( "test-data", "test.package.0001_0.1.0.tar.gz", package = "test.assessr" ) # Set up package source directory install_list <- set_up_pkg(dp) pkg_source_path <- install_list$pkg_source_path # Install locally to enable testing and coverage package_installed <- install_package_local(pkg_source_path) if (isTRUE(package_installed)) { coverage_results <- run_coverage(pkg_source_path) } # Restore user's original repository settings options(old)# Save and adjust CRAN mirror for reproducibility r <- getOption("repos") old <- options(repos = r) r["CRAN"] <- "http://cran.us.r-project.org" options(repos = r) # Example package from test.assessr dp <- system.file( "test-data", "test.package.0001_0.1.0.tar.gz", package = "test.assessr" ) # Set up package source directory install_list <- set_up_pkg(dp) pkg_source_path <- install_list$pkg_source_path # Install locally to enable testing and coverage package_installed <- install_package_local(pkg_source_path) if (isTRUE(package_installed)) { coverage_results <- run_coverage(pkg_source_path) } # Restore user's original repository settings options(old)
This function inspects the test configuration of an R package and runs code coverage analysis using any available testing framework, including 'testthat', 'testit', base R test scripts, or Bioconductor-style tests. If no recognised testing configuration is found, a default zero‑coverage result is returned.
run_covr_modes(pkg_source_path, covr_timeout = 60)run_covr_modes(pkg_source_path, covr_timeout = 60)
pkg_source_path |
Character. Path to the root directory of the package source. |
covr_timeout |
Numeric. Timeout in seconds for running coverage analysis. Default is 60. |
A named list containing coverage results, package metadata, and test configuration details. The returned list includes (but is not limited to):
Character. Package name extracted from the DESCRIPTION file.
Character. Package version.
Timestamp of when the analysis was run.
User or environment running the analysis.
System metadata.
R version used during analysis.
Character. Detected testing framework type.
A nested list containing:
Numeric. Aggregated coverage percentage.
File‑level and line‑level coverage details.
Any warnings or notes detected during testing.
A list describing the test configuration of the package (presence of testthat, testit, base tests, snapshots, etc.).
This function always returns a value. When no supported testing framework is detected, a default object with zero coverage and diagnostic information is returned.
dp <- system.file("test-data", "test.package.0001_0.1.0.tar.gz", package = "test.assessr") # set up package install_list <- set_up_pkg(dp) package_installed <- install_list$package_installed pkg_source_path <- install_list$pkg_source_path # install package locally to ensure test works package_installed <- install_package_local(pkg_source_path) package_installed <- TRUE covr_mode_list <- run_covr_modes(pkg_source_path)dp <- system.file("test-data", "test.package.0001_0.1.0.tar.gz", package = "test.assessr") # set up package install_list <- set_up_pkg(dp) package_installed <- install_list$package_installed pkg_source_path <- install_list$pkg_source_path # install package locally to ensure test works package_installed <- install_package_local(pkg_source_path) package_installed <- TRUE covr_mode_list <- run_covr_modes(pkg_source_path)
This function unpacks a package tarball using unpack_tarball() and
returns information about whether the unpacked directory exists. It is a
lightweight preparatory step used before attempting a local package
installation.
set_up_pkg(dp)set_up_pkg(dp)
dp |
Character string. Path to a package tarball or package directory. |
A named list with the following elements:
package_installed — Logical. TRUE if the unpacked
package directory exists, otherwise FALSE.
pkg_source_path — Character string giving the unpacked
package source directory, or "" if unpacking failed.
The returned object is always a base R list. It contains no side
effects besides calling unpack_tarball() and checking filesystem paths.
A value of package_installed = TRUE indicates that the unpacked
directory exists on disk and can be used for local installation.
package_installed = FALSE indicates either:
unpack_tarball() returned an empty result, or
the unpacked directory does not exist on disk.
## Not run: set_up_pkg(path/to/package, "mypackage") ## End(Not run)## Not run: set_up_pkg(path/to/package, "mypackage") ## End(Not run)