Skip to content

Commit 2daf863

Browse files
ehrlingerclaude
andauthored
fix: default S3 methods for the classic rfsrc/randomForest wrappers (3.4.1) (#139)
* fix: add default S3 methods to the classic rfsrc/randomForest wrappers (3.4.1) Post-release consistency pass. gg_error(), gg_vimp(), gg_variable(), gg_rfsrc(), and gg_brier() had no default S3 method, so a wrong-class input got R's generic "no applicable method" error. Add default methods emitting a clear "expected an 'rfsrc' or 'randomForest' object" message (naming the class received), matching the varPro-family cleanup done in 3.4.0. gg_roc() is intentionally left as-is: its default is aliased to gg_roc.rfsrc (accepts rfsrc-shaped objects); changing that is a behavior change, not a mechanical add. Additive only — no change to valid-input behavior. New fit-free dispatch test (runs on CRAN). Patch bump to 3.4.1 (DESCRIPTION + NEWS); will not be submitted immediately (CRAN discourages back-to-back updates) — it starts the post-3.4.0 dev line on main. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(cran): record 3.4.0 submission (SHA 16c8b4d) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 89a10d7 commit 2daf863

10 files changed

Lines changed: 71 additions & 6 deletions

File tree

CRAN-SUBMISSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 3.2.0
2-
Date: 2026-06-23 16:43:46 UTC
3-
SHA: 9892d5abc8c9278acd19835059bbe78ff887c7bc
1+
Version: 3.4.0
2+
Date: 2026-07-02 16:27:59 UTC
3+
SHA: 16c8b4d791827785b68e78279b89c183b9d35d09

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: ggRandomForests
22
Type: Package
33
Title: Visually Exploring Random Forests
4-
Version: 3.4.0
5-
Date: 2026-07-01
4+
Version: 3.4.1
5+
Date: 2026-07-02
66
Authors@R: person("John", "Ehrlinger",
77
role = c("aut", "cre"),
88
email = "john.ehrlinger@gmail.com")

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ S3method(gg_beta_uvarpro,default)
2424
S3method(gg_beta_uvarpro,uvarpro)
2525
S3method(gg_beta_varpro,default)
2626
S3method(gg_beta_varpro,varpro)
27+
S3method(gg_brier,default)
2728
S3method(gg_brier,rfsrc)
29+
S3method(gg_error,default)
2830
S3method(gg_error,randomForest)
2931
S3method(gg_error,randomForest.formula)
3032
S3method(gg_error,rfsrc)
3133
S3method(gg_isopro,default)
3234
S3method(gg_isopro,isopro)
3335
S3method(gg_ivarpro,default)
3436
S3method(gg_ivarpro,varpro)
37+
S3method(gg_rfsrc,default)
3538
S3method(gg_rfsrc,randomForest)
3639
S3method(gg_rfsrc,rfsrc)
3740
S3method(gg_roc,default)
@@ -41,8 +44,10 @@ S3method(gg_sdependent,default)
4144
S3method(gg_sdependent,uvarpro)
4245
S3method(gg_survival,default)
4346
S3method(gg_survival,rfsrc)
47+
S3method(gg_variable,default)
4448
S3method(gg_variable,randomForest)
4549
S3method(gg_variable,rfsrc)
50+
S3method(gg_vimp,default)
4651
S3method(gg_vimp,randomForest)
4752
S3method(gg_vimp,rfsrc)
4853
S3method(plot,gg_beta_uvarpro)

NEWS.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
Package: ggRandomForests
2-
Version: 3.4.0
2+
Version: 3.4.1
3+
4+
ggRandomForests v3.4.1
5+
======================
6+
* The remaining `rfsrc`/`randomForest` wrappers -- `gg_error()`, `gg_vimp()`,
7+
`gg_variable()`, `gg_rfsrc()`, and `gg_brier()` -- now have `default` S3
8+
methods, so a wrong-class input gives a clear "expected an 'rfsrc' or
9+
'randomForest' object" error (naming the class it got) instead of R's generic
10+
"no applicable method". This finishes the dispatch-consistency pass started
11+
for the varPro family in 3.4.0. (`gg_roc()` keeps its existing
12+
`gg_roc.rfsrc` default, which accepts rfsrc-shaped objects.)
313

414
ggRandomForests v3.4.0
515
======================

R/gg_brier.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ gg_brier <- function(object, ...) {
119119
UseMethod("gg_brier", object)
120120
}
121121

122+
#' @export
123+
gg_brier.default <- function(object, ...) {
124+
stop("gg_brier: expected an 'rfsrc' survival object from ",
125+
"randomForestSRC::rfsrc(); got an object of class ",
126+
paste(class(object), collapse = "/"), ".", call. = FALSE)
127+
}
128+
122129
#' @export
123130
gg_brier.rfsrc <- function(object,
124131
subset = NULL,

R/gg_error.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@
204204
gg_error <- function(object, ...) {
205205
UseMethod("gg_error", object)
206206
}
207+
208+
#' @export
209+
gg_error.default <- function(object, ...) {
210+
stop("gg_error: expected an 'rfsrc' or 'randomForest' object; ",
211+
"got an object of class ", paste(class(object), collapse = "/"), ".",
212+
call. = FALSE)
213+
}
207214
#' @export
208215
gg_error.rfsrc <- function(object, ...) {
209216
## Check that the input object is of the correct type.

R/gg_rfsrc.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ gg_rfsrc <- function(object,
454454
UseMethod("gg_rfsrc", object)
455455
}
456456

457+
#' @export
458+
gg_rfsrc.default <- function(object, oob = TRUE, by, ...) {
459+
stop("gg_rfsrc: expected an 'rfsrc' or 'randomForest' object; ",
460+
"got an object of class ", paste(class(object), collapse = "/"), ".",
461+
call. = FALSE)
462+
}
463+
457464
#' @export
458465
gg_rfsrc.randomForest <- function(object,
459466
oob = TRUE,

R/gg_variable.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@
159159
gg_variable <- function(object, ...) {
160160
UseMethod("gg_variable", object)
161161
}
162+
163+
#' @export
164+
gg_variable.default <- function(object, ...) {
165+
stop("gg_variable: expected an 'rfsrc' or 'randomForest' object; ",
166+
"got an object of class ", paste(class(object), collapse = "/"), ".",
167+
call. = FALSE)
168+
}
162169
#' @export
163170
gg_variable.rfsrc <- function(object,
164171
...) {

R/gg_vimp.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@
190190
gg_vimp <- function(object, nvar, ...) {
191191
UseMethod("gg_vimp", object)
192192
}
193+
194+
#' @export
195+
gg_vimp.default <- function(object, nvar, ...) {
196+
stop("gg_vimp: expected an 'rfsrc' or 'randomForest' object; ",
197+
"got an object of class ", paste(class(object), collapse = "/"), ".",
198+
call. = FALSE)
199+
}
193200
#' @export
194201
gg_vimp.rfsrc <- function(object, nvar, ...) {
195202
# Validate that the object is an rfsrc grow or predict result.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Wrong-class inputs to the rfsrc/randomForest wrappers must error via their
2+
# default S3 methods with a clear message. Fit-free, so these run on CRAN.
3+
4+
test_that("rfsrc/randomForest wrappers error on non-model input", {
5+
bad <- data.frame(a = 1:3)
6+
7+
expect_error(gg_error(bad), "expected an 'rfsrc' or 'randomForest' object")
8+
expect_error(gg_vimp(bad), "expected an 'rfsrc' or 'randomForest' object")
9+
expect_error(gg_variable(bad), "expected an 'rfsrc' or 'randomForest' object")
10+
expect_error(gg_rfsrc(bad), "expected an 'rfsrc' or 'randomForest' object")
11+
expect_error(gg_brier(bad), "expected an 'rfsrc' survival object")
12+
13+
# The error names the class it actually got.
14+
expect_error(gg_error(1:3), "got an object of class integer")
15+
})

0 commit comments

Comments
 (0)