title: Error when using predict() on a randomForest object trained with caret's train() using formula
body: <p>Using R 3.2.0 with caret 6.0-41 and randomForest 4.6-10 on a 64-bit Linux machine.</p>
  
  <p>When trying to use the <code>predict()</code> method on a <code>randomForest</code> object trained with the <code>train()</code> function from the <code>caret</code> package using a formula, the function returns an error.
  When training via <code>randomForest()</code> and/or using <code>x=</code> and <code>y=</code> rather than a formula, it all runs smoothly.</p>
  
  <p>Here is a working example:</p>
  
  <pre><code>library(randomForest)
  library(caret)
  
  data(imports85)
  imp85     &lt;- imports85[, c("stroke", "price", "fuelType", "numOfDoors")]
  imp85     &lt;- imp85[complete.cases(imp85), ]
  imp85[]   &lt;- lapply(imp85, function(x) if (is.factor(x)) x[,drop=TRUE] else x) ## Drop empty levels for factors.
  
  modRf1  &lt;- randomForest(numOfDoors~., data=imp85)
  caretRf &lt;- train( numOfDoors~., data=imp85, method = "rf" )
  modRf2  &lt;- caretRf$finalModel
  modRf3  &lt;- randomForest(x=imp85[,c("stroke", "price", "fuelType")], y=imp85[, "numOfDoors"])
  caretRf &lt;- train(x=imp85[,c("stroke", "price", "fuelType")], y=imp85[, "numOfDoors"], method = "rf")
  modRf4  &lt;- caretRf$finalModel
  
  p1      &lt;- predict(modRf1, newdata=imp85)
  p2      &lt;- predict(modRf2, newdata=imp85)
  p3      &lt;- predict(modRf3, newdata=imp85)
  p4      &lt;- predict(modRf4, newdata=imp85)
  </code></pre>
  
  <p>Among the last 4 lines, only the second one <code>p2 &lt;- predict(modRf2, newdata=imp85)</code> returns the following error:</p>
  
  <pre><code>Error in predict.randomForest(modRf2, newdata = imp85) : 
  variables in the training data missing in newdata
  </code></pre>
  
  <p>It seems that the reason for this error is that the <code>predict.randomForest</code> method uses <code>rownames(object$importance)</code> to determine the name of the variables used to train the random forest <code>object</code>. And when looking at</p>
  
  <pre><code>rownames(modRf1$importance)
  rownames(modRf2$importance)
  rownames(modRf3$importance)
  rownames(modRf4$importance)
  </code></pre>
  
  <p>We see:</p>
  
  <pre><code>[1] "stroke"   "price"    "fuelType"
  [1] "stroke"   "price"    "fuelTypegas"
  [1] "stroke"   "price"    "fuelType"
  [1] "stroke"   "price"    "fuelType"
  </code></pre>
  
  <p>So somehow, when using the <code>caret</code> <code>train()</code> function with a formula changes the name of the (factor) variables in the <code>importance</code> field of the <code>randomForest</code> object.</p>
  
  <p>Is it really an inconsistency between the formula and and non-formula version of the caret <code>train()</code> function? Or am I missing something?</p>