Your code works without problems for me in current versions of R and party
. Moreover, the offending piece of code mget(plabels[hasSubclass], env)
is not in the party
package but it comes from the basic methods
package which is used by party
. My suspicion is that your installation is out of sync in some way, e.g., you did not re-install the packages in your library after upgrading your R version or something similar. So you could try to run update.packages(..., checkBuilt = TRUE)
or something along those lines to reinstall the packages in your libraries. Hopefully, this should fix the issue above.
Another comment regarding your artificial example: The variable y
is a numeric 0/1 dummy variable but I assume you really want to do classification rather than regression. So I would recommend to do
df$y <- factor(df$y)
prior to fitting the cforest()
. This will assure that the appropriate test statistics are used during the learning of the tree - and the correct predictions are produced etc.