Skip to content

fix: plot.gg_variable default multi-class render error (yvar not found)#93

Merged
ehrlinger merged 3 commits into
mainfrom
fix/plot-gg-variable-yvar-render
May 26, 2026
Merged

fix: plot.gg_variable default multi-class render error (yvar not found)#93
ehrlinger merged 3 commits into
mainfrom
fix/plot-gg-variable-yvar-render

Conversation

@ehrlinger
Copy link
Copy Markdown
Owner

Summary

plot(gg_variable(rf_classification)) (default — no xvar) errored at render time on a multi-class randomForest classification forest:

Problem while computing aesthetics. … Column `yvar` not found in `.data`.

Root cause: the default-xvar selection in plot.gg_variable excluded yhat/event/time columns but not yvar (the observed-class response column added by gg_variable for classification) or outcome (the facet column added by the multi-class pivot). Both got iterated as predictors and pivoted into var, dropping the column the downstream geom_jitter(aes(color = yvar)) needed.

Invisible to CI because the existing test only asserted patchwork class (lazy — never builds the sub-plots) and vdiffr snapshots run with VDIFFR_RUN_TESTS = false.

Fix

  • Add yvar and outcome to the default-xvar exclusion list in R/plot.gg_variable.R.
  • New regression test exercises an actual ggplot_build on every patchwork sub-plot — this is what catches it.

Test plan

  • New test fails on the bug (verified before the fix), passes after
  • devtools::test(filter = 'gg_variable') — 0 failures
  • devtools::check(args = "--as-cran") — 0 errors, 0 warnings, 0 notes

🤖 Generated with Claude Code

…not predictors)

The default-xvar selection in plot.gg_variable stripped only yhat/event/time
columns, leaving yvar (the response factor added by gg_variable for
classification) and outcome (the facet column added by the multi-class pivot)
to be treated as predictors. They were then pivoted into `var`, dropping the
column the downstream geom_jitter aes referenced, and the patchwork errored
when actually rendered with "Column `yvar` not found in `.data`".

Invisible to CI: the existing test only asserted patchwork class (lazy),
and vdiffr snapshots run with VDIFFR_RUN_TESTS=false. New test exercises a
real ggplot_build on every patchwork sub-plot.

Add yvar and outcome to the exclusion list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.31%. Comparing base (4852ab8) to head (93d0298).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
- Coverage   87.31%   87.31%   -0.01%     
==========================================
  Files          38       38              
  Lines        3098     3097       -1     
==========================================
- Hits         2705     2704       -1     
  Misses        393      393              
Files with missing lines Coverage Δ
R/plot.gg_variable.R 82.08% <100.00%> (-0.06%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a render-time failure when plotting multi-class gg_variable outputs with default xvar selection, by ensuring response/structural columns aren’t accidentally treated as predictors and by adding a regression test that forces patchwork subplots to build.

Changes:

  • Exclude yvar and outcome from the default xvar candidate set in plot.gg_variable().
  • Add a regression test that calls ggplot_build() on each patchwork subplot for a multi-class randomForest classification.
  • Document the fix in NEWS.md and bump package version.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/testthat/test_gg_variable.R Adds a regression test that forces patchwork panels to build to catch render-time aesthetic errors.
R/plot.gg_variable.R Adjusts default xvar exclusion list to avoid pivoting away columns needed for downstream aesthetics in multi-class plots.
NEWS.md Adds a changelog entry describing the bug and the new test coverage.
DESCRIPTION Bumps the development version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/plot.gg_variable.R
…grep)

Copilot review caught a latent bug I inherited when fixing the yvar/outcome
issue: grep("time", colnames(gg_dta)) silently excludes any predictor whose
name contains the substring "time" -- the documented veteran-data survival
predictor `diagtime` was being dropped from the default xvar list. Same for
grep("event", ...) on any predictor containing "event".

Switch the exclusion to exact name matching for event/time/yvar/outcome via
%in%, and anchor the yhat match as ^yhat(\\.|$) so it still catches both the
bare yhat column (regression / single-class survival) and the yhat.<class>
columns (classification gg_variable). New test on the veteran survival
forest confirms diagtime is included as a panel.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ehrlinger ehrlinger merged commit af0405c into main May 26, 2026
15 checks passed
@ehrlinger ehrlinger deleted the fix/plot-gg-variable-yvar-render branch May 28, 2026 14:33
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