Inside a function, I want to set a variable to either the corresponding argument, or a default value if that argument is NULL. The code is as follows:
rcontrol <- ifelse(is.null(rcontrol),rpart.control(cp=0.001,minbucket=100,minsplit = 5),rcontrol)
It took me a long time to figure out that the rcontrol
isn't the same as if it were defined in this way:
rcontrol <- rpart.control(cp=0.001,minbucket=100,minsplit = 5)
Can anyone please explain this bizarre behavior of ifelse
?