R version 3.6.1 (2019-07-05) -- "Action of the Toes" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## https://github.com/bethatkinson/rpart/issues/7 > > library(rpart) > mtcars2 <- mtcars > > mtcars2$gear <- factor(mtcars2$gear) > mtcars2$carb <- factor(mtcars2$carb) > > set.seed(10) > rp1 <- rpart(mpg ~ . - gear, data = mtcars2) > set.seed(10) > rp2 <- rpart(mpg ~ ., data = mtcars2[names(mtcars2) != "gear"]) > > all.equal(rp1[setdiff(names(rp1), c("call", "terms"))], + rp2[setdiff(names(rp2), c("call", "terms"))], check.attributes=FALSE) [1] TRUE > > > set.seed(10) > rp3 <- rpart(mpg ~ . - gear - carb, data = mtcars2) > set.seed(10) > rp4 <- rpart(mpg ~ ., data = mtcars2[setdiff(names(mtcars2), c("gear", "carb"))]) > > all.equal(rp3[setdiff(names(rp3), c("call", "terms"))], + rp4[setdiff(names(rp4), c("call", "terms"))], check.attributes=FALSE) [1] TRUE > > proc.time() user system elapsed 0.167 0.052 0.236