borg_inspect() examines R objects for signals of information reuse that
would invalidate model evaluation. It returns a structured assessment of
detected risks.
Usage
borg_inspect(
object,
train_idx = NULL,
test_idx = NULL,
data = NULL,
target = NULL,
coords = NULL,
...
)Arguments
- object
An R object to inspect. Supported types include:
Preprocessing:
preProcess,recipe,prcomp, and basescale()output (a matrix carrying the"scaled:center"/"scaled:scale"attributes, or a data frame whose columns were replaced byscale()output)CV objects:
trainControl,rsplit,vfold_cvModel objects:
train,lm,glmData frames with train/test split information
- train_idx
Integer vector of training row indices. Required for data-level inspection.
- test_idx
Integer vector of test row indices. Required for data-level inspection.
- data
Optional data frame. Required when inspecting preprocessing objects to compare parameters against train-only statistics.
- target
Optional name of the target/outcome column. If provided, checks for target leakage (features highly correlated with target).
- coords
Optional character vector of coordinate column names. If provided, checks spatial separation between train and test.
- ...
Additional arguments passed to type-specific inspectors.
Value
A BorgRisk object containing:
- risks
List of detected risk objects
- n_hard
Count of hard violations
- n_soft
Count of soft inflation warnings
- is_valid
TRUE if no hard violations detected
Details
borg_inspect() dispatches to type-specific inspectors based on the class
of the input object. Each inspector looks for specific leakage patterns:
- Preprocessing objects
Checks if parameters (mean, sd, loadings) were computed on data that includes test indices
- CV objects
Validates that train/test indices do not overlap and that grouping structure is respected
- Feature engineering
Checks if encodings, embeddings, or derived features used test data during computation
See also
borg_validate for complete workflow validation,
borg for automated enforcement during evaluation.
Examples
# Inspect a preprocessing object
data(mtcars)
train_idx <- 1:25
test_idx <- 26:32
# BAD: standardisation fitted on full data (detected as a leak)
pp_bad <- scale(mtcars[, -1])
borg_inspect(pp_bad, train_idx = train_idx, test_idx = test_idx)
# GOOD: standardisation fitted on train only
pp_good <- scale(mtcars[train_idx, -1])
borg_inspect(pp_good, train_idx = train_idx, test_idx = test_idx)