Skip to content

fix: map randomForest 'classification' type to 'class' in gg_variable class attr#90

Merged
ehrlinger merged 2 commits into
mainfrom
fix/gg-variable-rf-class-attr
May 21, 2026
Merged

fix: map randomForest 'classification' type to 'class' in gg_variable class attr#90
ehrlinger merged 2 commits into
mainfrom
fix/gg-variable-rf-class-attr

Conversation

@ehrlinger
Copy link
Copy Markdown
Owner

Summary

  • gg_variable.randomForest() appended object$type ("classification") to the class vector of the result, but plot.gg_variable's dispatcher and the rfsrc path both use "class" to identify classification forests
  • This was accidentally correct (the dispatcher fell through to the "class" default), but fragile — any inherits(gg_dta, "class") check would silently fail
  • Maps "classification""class" at the point of assignment with an explanatory comment; all other object$type values pass through unchanged

Test plan

  • New test: "class" %in% class(gg_variable(rf_iris)) is TRUE
  • New test: "classification" %in% class(gg_variable(rf_iris)) is FALSE
  • Full test_gg_variable.R suite passes (42 tests)

Notes

Depends on nothing; safe to merge before or after PR #87/#88. The real-world impact is minimal today (dispatcher falls through to the same default) but the explicit mapping removes a latent surprise.

🤖 Generated with Claude Code

… class attr

randomForest stores family as object$type ("classification"), but the
plot.gg_variable dispatcher and the rfsrc path both use "class".  Add an
explicit mapping so the class vector is consistent across engines and callers
never need to special-case "classification".

Adds one test verifying "class" is present and "classification" is absent.

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

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.39%. Comparing base (7e4197c) to head (30e3a45).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #90   +/-   ##
=======================================
  Coverage   86.39%   86.39%           
=======================================
  Files          38       38           
  Lines        3021     3022    +1     
=======================================
+ Hits         2610     2611    +1     
  Misses        411      411           
Files with missing lines Coverage Δ
R/gg_variable.R 82.55% <100.00%> (+0.20%) ⬆️
🚀 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

This pull request standardizes the S3 class attribute applied by gg_variable.randomForest() so that randomForest classification models use "class" (matching the rfsrc path and plot.gg_variable’s family detection) instead of "classification".

Changes:

  • Map object$type == "classification" to "class" when building the gg_variable class vector for randomForest models.
  • Add a unit test asserting "class" is present and "classification" is absent from class(gg_variable(rf_iris)).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
R/gg_variable.R Maps randomForest "classification" type to "class" in the returned object’s S3 class vector for consistent downstream dispatch.
tests/testthat/test_gg_variable.R Adds a regression test ensuring the class mapping is applied for randomForest classification models.

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

@ehrlinger ehrlinger merged commit cf6229a into main May 21, 2026
19 checks passed
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