title: Caret and GBM: task 1 failed - "arguments imply differing number of rows"
body: <p>I'm trying to run a GBM with caret with the code below:</p>
  
  <pre><code>library(caret)
  library(doParallel)
  detectCores()
  registerDoParallel(detectCores() - 1)
  
  set.seed(668)
  in.train &lt;- createDataPartition(y = dat$target, p = 0.80, list = T)
  
  ctrl &lt;- trainControl(method = 'cv', number = 2, classProbs = T, verboseIter = T,
                   summaryFunction = LogLossSummary2)
  
  gbm.grid &lt;- expand.grid(interaction.depth = 10,
                          n.trees = (2:7) * 50,
                          shrinkage = 0.1)
  
  Sys.time()
  set.seed(1234)
  gbm.fit &lt;- train(target ~., data = otto.new[in.train, ], 
                   method = 'gbm', distribution = 'multinomial', 
                   metric = 'LogLoss', maximize = F, 
                   tuneGrid = gbm.grid, trControl = ctrl,
                   n.minobsinnode = 4, bag.fraction = 0.9)
  Sys.time()
  </code></pre>
  
  <p>However, it fails with the error: </p>
  
  <pre><code>Error in { : 
  task 1 failed - "arguments imply differing number of rows: 0, 24754"
  In addition: Warning messages:
  1: package ‘gbm’ was built under R version 3.0.3 
  2: package ‘survival’ was built under R version 3.0.3 
  3: package ‘plyr’ was built under R version 3.0.3 
  </code></pre>
  
  <p>Here's my session info:</p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.0.2 (2013-09-25)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  
  locale:
  [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252     LC_MONETARY=English_United States.1252
  [4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
  
  attached base packages:
  [1] splines   parallel  stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] plyr_1.8.1       gbm_2.1.1        survival_2.38-1  doParallel_1.0.8 iterators_1.0.7  foreach_1.4.2    data.table_1.9.4
  [8] caret_6.0-41     ggplot2_1.0.1    Revobase_7.1.0   RevoMods_7.1.0   RevoScaleR_7.1.0 lattice_0.20-27  rpart_4.1-5     
  
  loaded via a namespace (and not attached):
  [1] BradleyTerry2_1.0-6 brglm_0.5-9         car_2.0-25          chron_2.3-45        class_7.3-12        codetools_0.2-11   
  [7] colorspace_1.2-6    compiler_3.0.2      digest_0.6.8        e1071_1.6-4         grid_3.0.2          gtable_0.1.2       
  [13] gtools_3.4.1        lme4_1.1-7          MASS_7.3-37         Matrix_1.1-5         mgcv_1.8-5          minqa_1.2.4        
  [19] munsell_0.4.2       nlme_3.1-120        nloptr_1.0.4        nnet_7.3-9           pbkrtest_0.4-2      proto_0.3-10       
  [25] quantreg_5.11       Rcpp_0.11.5         reshape2_1.4.1      scales_0.2.4            SparseM_1.6         stringr_0.6.2      
  [31] tools_3.0.2        
  </code></pre>
  
  <p>I've noticed that this issue happens intermittently and seems to be reduced when I ensure that my dataset is a multiple of k-folds.  (In the case above, my dataset has 49506 rows).  Nonetheless, it seems to crop up every now and then.  Has anyone else encountered this and come across a way to prevent it?</p>