Skip to content

Added unit tests for arg checks, prep, Fisher, core ML, and pipeline#20

Merged
eboyer221 merged 5 commits into
mainfrom
testing
May 22, 2026
Merged

Added unit tests for arg checks, prep, Fisher, core ML, and pipeline#20
eboyer221 merged 5 commits into
mainfrom
testing

Conversation

@eboyer221
Copy link
Copy Markdown
Contributor

@eboyer221 eboyer221 commented Apr 15, 2026

Summary

Adds a testthat test suite covering helpers and the full runMLPipeline() flow.

Coverage

  • tests/testthat/test-arg-checks.R : every internal .checkArg* validator in R/arg_check_ml.R
  • tests/testthat/test-prep-ml.R : .getTargetVarName, getNumFeat, shuffleLabels, calculateMinSamples, loadMLInputTibble.
  • tests/testthat/test-fisher.R : encodePhenotype, runFisherTests, applyBenjaminiHochberg, computeFeatureFreq.
  • tests/testthat/test-core-ml.R : splitMLInputTibble, buildRecipe, buildLRModel, buildWflow, buildTuningGrid, predictML / getConfusionMatrix / calculateEvalMets/ extractTopFeats.
  • tests/testthat/test-pipeline.R : end-to-end runMLPipeline() with cross-validation instead of a train/validation/test split: output structure, signal recovery, return_fit / return_pred / return_tune_res, shuffle_labels baseline, multi-class rejection for non-LR models, removeTopFeats.

Helpers in helper-fixtures.R and helper-ml-fixture.R build small tibbles for fast pipeline tests.

Known issue -

This note is just a heads-up that the tests uncovered a pre-existing bug in runMLPipeline() that's worth fixing in a follow-up PR:
When you call runMLPipeline() with a train/validation/test split (e.g. split = c(0.6, 0.2)), it crashes. The pipeline turns off cross-validation in this mode, but the tuning step still tries to run cross-validation and errors out. Until that's fixed, the pipeline tests only cover the cross-validation mode (split = c(1, 0)). The tests are sufficient as-is so no action should be needed from the reviewer to merge them - this is just a note for a future fix.

How to run the tests

Locally, from the package root (amRml/):

# Option A — devtools (recommended during development)
devtools::test()

# Option B — R CMD check (full package check, including tests)
devtools::check()

Or from the shell:
cd amRml
Rscript -e 'devtools::test()'
Expected: [ FAIL 0 | WARN 0 | SKIP 0 | PASS 200 ].

@eboyer221 eboyer221 requested review from AbhirupaGhosh, amcim, charmvang, epbrenner, jananiravi and klterwelp and removed request for klterwelp April 15, 2026 17:29
@amcim
Copy link
Copy Markdown
Contributor

amcim commented May 22, 2026

@eboyer221 I looked into the preexisting train/validation/test split bug and added a test showing that runMLPipeline() now returns the expected structure with split = c(0.6, 0.2).

The change is line 264 of core_ml.R where initial_validation_split now uses:

rsample::validation_set(data_split)

instead of calling vfold_cv().

In run_ml_pipeline.R, there is this conditional for when 0 is passed is for the split where the nfold is set to NA.

  # Set `n_fold` to `NA` if not using cross-validation.
  if (split[2] != 0) {
    n_fold <- NA
  }

The crash was because the original vfold_cv should not be taking an NA for the number of folds, in this mode the existing validation partition should be used rather than creating new folds. I ran with the validation split and a cv split and I see similar, overlapping top importance score features.

If this solution makes sense to you, ill approve for merging

@eboyer221 eboyer221 merged commit 9a79c0c into main May 22, 2026
7 checks passed
@eboyer221 eboyer221 deleted the testing branch May 22, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants