Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class inheritance should be changed to c("partial", "data.frame") instead of c("data.frame", "partial") #104

Closed
RoelVerbelen opened this issue Feb 19, 2020 · 3 comments

Comments

@RoelVerbelen
Copy link

I'm experiencing unexpected errors as a result of the order of the classes of a partial object. I believe they can be addressed by changing the order of the classes of a partial object such that the inheritance of methods works as expected.

For reference:
http://adv-r.had.co.nz/S3.html
https://adv-r.hadley.nz/s3.html#s3-inheritance

# Construct partial object
library(pdp)
library(randomForest)
data(boston)  
set.seed(101)  
boston.rf <- randomForest(cmedv ~ ., data = boston)
pd <- partial(boston.rf, pred.var = c("lstat", "rm"), grid.resolution = 40)

# Inspect class
class(pd)
#> [1] "data.frame" "partial"

# Data manipulation fails
library(dplyr)
pd %>% 
  select(yhat)
#> Error: `x` must be a vector, not a `data.frame/partial` object

# Change class
class(pd) <- c("partial", "data.frame")

# Data manipulation works
pd %>% 
  select(yhat) %>% 
  head()
#>       yhat
#> 1 29.57550
#> 2 29.57337
#> 3 29.28864
#> 4 27.49390
#> 5 25.15407
#> 6 24.74364

# And partial specific functions still work as expected
plotPartial(pd, levelplot = FALSE, zlab = "cmedv", drape = TRUE,
            colorkey = FALSE, screen = list(z = -20, x = -60))

Created on 2020-02-19 by the reprex package (v0.3.0)

@bgreenwell
Copy link
Owner

Thanks @RoelVerbelen for the helpful reprex. I’m on travel this week, but will push a fix soon. I also anticipate updating the version on CRAN by the end of March.

@bgreenwell
Copy link
Owner

Thanks @RoelVerbelen for the reprex! I'm on travel right now, but will push an update early next week. I should have a long overdue update to CRAN by the end of March as well.

@bgreenwell
Copy link
Owner

Actually, @RoelVerbelen, it looks like this was already fixed back in December and has been part of the development version since (albeit, undocumented in NEWS.md)! Working on a CRAN release this week and next.

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

No branches or pull requests

2 participants