
Reduce a failure in paired experimental data
Source:R/reduce_paired_failure.R
reduce_paired_failure.RdPilot reduction for a SummarizedExperiment with exactly two conditions and one sample per condition in every pair. Remove assay rows and whole pairs while keeping the original order. Subsetting uses the container's methods and retains its assay backend.
Arguments
- x
A SummarizedExperiment::SummarizedExperiment with paired samples.
- pair, condition
Names of columns in the sample metadata.
- design
One-sided additive formula using columns in sample metadata.
- check
Function taking one SummarizedExperiment and returning a nonempty character string identifying a failure, or
NULL.- seed
Integer seed for the checker.
- max_checks
Maximum number of checker calls, including the original and final checks. At least two.
Value
A list containing data, the checked subset, rows and columns
(indices in the original object), failure (the matched identifier),
checks (the number of checker calls) and budget_exhausted.
Details
The design must be an additive, one-sided formula with the pair and condition as main effects. Additional plain numeric or categorical covariates are supported. Each candidate retains all observed levels of non-pair categorical covariates, a full-rank design matrix and positive residual degrees of freedom. The matrix uses the current R contrast options. Pair and condition labels must be characters or factors, and the pair factor must be unordered. Unused pair levels are dropped when pairs are removed. Drop unused factor levels before supplying the original object. Pair factors use the current contrast options and cannot have custom contrasts. Include any extra constraints, such as a minimum number of pairs per stratum, in the checker.
The checker should run the operation and return a stable identifier
for the specific failure, or NULL if it does not occur. Use different
identifiers for different failures. An unexpected error in the checker
stops reduction. The checker should be repeatable and free of side
effects. The same base R seed is used for each check. Set any
backend-specific seed in the checker if needed.
The original and the final subset are checked explicitly. The search is greedy and bounded; it may leave removable rows or pairs. Review the reduced object before using it as an ordinary test fixture.
Examples
if (requireNamespace("SummarizedExperiment", quietly = TRUE)) {
counts <- matrix(1:24, nrow = 4)
samples <- data.frame(
subject = rep(letters[1:3], each = 2),
visit = rep(c("before", "after"), times = 3)
)
x <- SummarizedExperiment::SummarizedExperiment(
assays = list(counts = counts), colData = samples
)
assert_counts <- function(data) {
if (any(SummarizedExperiment::assay(data) == 16L)) {
stop(errorCondition("Sentinel count rejected", class = "sentinel_count"))
}
}
check <- function(data) {
tryCatch({
assert_counts(data)
NULL
}, sentinel_count = function(cnd) "sentinel count rejected")
}
reduced <- reduce_paired_failure(x, "subject", "visit", ~ subject + visit, check)
check(reduced$data)
}
#> [1] "sentinel count rejected"