I'd like to create a function to display the result of rpart
with partykit
.
I converted the result of rpart
with as.party
with the following code and displayed the tree structure.
library(partykit)
library(rpart)
result1 <- rpart(Species~.,data = iris)
plot(as.party(result1))
So, I defined rpart and as.party in the function and executed it.
rpart_party <- function(formula, data){
result1 <- rpart(formula = formula ,data = data)
return(as.party(result1))
}
plot(rpart_party(Species~., data = iris))
However, the following error occurred.
Error in eval(predvars, data, env) : invalid 'envir' argument of type 'closure'
Please tell me how to create a function that transforms the result of rpart
with as.party
and displays the structure of the tree.