Tuesday, July 9, 2013

Error due to partykit

I'm a frequent user of the R package party. Recently, the R package partykit was created by the authors of party, for 'representing, summarizing, and visualizing tree-structured regression and classification models'. And all of a sudden, the where function didn't function anymore, and the following error message gets printed:

Error in function (classes, fdef, mtable)  :
  unable to find an inherited method for function "where", for signature "constparty"


This is due to changes in the structure of the BinaryTree Class in partykit package. See following code for fixing this problem.

library(party)
library(partykit)
airq <- subset(airquality, !is.na(Ozone))
airct <- ctree(Ozone ~ ., data = airq)
where(airct)
# Error!
# Fix error:
detach("package:partykit", unload=TRUE)
airct <- ctree(Ozone ~ ., data = airq) # you have to rebuild the tree
where(airct) # now it works!

No comments:

Post a Comment