r-lib / generics

Common generic methods
https://generics.r-lib.org/
Other
61 stars 13 forks source link

`generics::prune()` seems to cause an error for `rpart::prune.rpart()` #79

Closed RoelVerbelen closed 17 hours ago

RoelVerbelen commented 2 weeks ago

Just running it this issue I though I'd flag here:

library(rpart)
library(generics)
#> 
#> Attaching package: 'generics'
#> The following object is masked from 'package:rpart':
#> 
#>     prune
#> The following objects are masked from 'package:base':
#> 
#>     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
#>     setequal, union

z.auto <- rpart(Mileage ~ Weight, car.test.frame)
zp <- prune(z.auto, cp = 0.1)
#> Error in UseMethod("prune"): no applicable method for 'prune' applied to an object of class "rpart"

Created on 2024-10-03 with reprex v2.1.1

topepo commented 21 hours ago

Honestly, I don't know why that occurs; the functions are the same.

However, we would call it "off-label use" since generics should never be fully loaded. The intent is to import it and then create new S3 methods (in this case, without loading rpart).