Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[R-Forge #5660] Interaction between "Caret" package and data.table in R 3.1 gives different column name #476
However, the fix doesn't seem to be working. Here's what I get on my system:
library(caret) library(data.table) DT <- data.table(x = rnorm(10), y = rnorm(10)) cv.ctrl <- trainControl(method = 'repeatedcv', number = 5, repeats = 1) fit <- train(y ~ x, data = DT, 'lm', trControl = cv.ctrl) > names(DT) #  "x" ".outcome" > sessionInfo() # R version 3.1.1 (2014-07-10) # Platform: x86_64-apple-darwin10.8.0 (64-bit) # locale: #  en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 # attached base packages: #  graphics grDevices datasets stats utils methods base # other attached packages: #  data.table_1.9.3 caret_6.0-30 ggplot2_1.0.0 lattice_0.20-29 bit64_0.9-4 #  bit_1.1-12 # loaded via a namespace (and not attached): #  BradleyTerry2_1.0-5 brglm_0.5-9 car_2.0-20 codetools_0.2-8 #  colorspace_1.2-4 compiler_3.1.1 digest_0.6.4 foreach_1.4.2 #  grid_3.1.1 gtable_0.1.2 gtools_3.4.1 iterators_1.0.7 #  lme4_1.1-7 MASS_7.3-33 Matrix_1.1-4 minqa_1.2.3 #  munsell_0.4.2 nlme_3.1-117 nloptr_1.0.0 nnet_7.3-8 #  plyr_1.8.1 proto_0.3-10 Rcpp_0.11.2 reshape2_22.214.171.124 #  scales_0.2.4 splines_3.1.1 stringr_0.6.2 tools_3.1.1
The issue seems to arise from these lines from
res$trainingData <- data isY <- names(res$trainingData) %in% as.character(form[]) if(any(isY)) colnames(res$trainingData)[isY] <- ".outcome"
which should work just fine, except it doesn't on v3.1+. It works just fine with < v3.1. This is because R v3.1+ shallow copies where ever possible as opposed to deep copies and
# R v3.1.1 require(data.table) dt = data.table(x=1:5, y=6:10) ll = vector("list", 2L) names(ll) <- c("a", "b") ll$a = 1L; ll$b = dt idx = c(FALSE, TRUE) colnames(ll$b)[idx] = "bla" names(dt) #  "x" "bla" names(ll$b) #  "x" "bla"
Bumping priority. Assigning milestone 1.9.4.