title: Illegal column names error yet column names are legal
body: <p>Wondering why I get this error. I can only reproduce it if I make the levels within my data frame illegal column names, but why does it work in the RF implementation? </p>
  
  <p>Thinking about using ranger as it seems to run faster.</p>
  
  <pre><code>library(caret)
  library(ranger)
  library(randomForest)
  
  df &lt;- data.frame(class = c(rep(c('A','B'), 10)), var1 = runif(20, 0,10), var2 = runif(20, 0,20), var3 = c(rep(c(' A','1 B', 'C'), 6), 'D','D'))
  df
  
  CTRL &lt;- trainControl(method = "repeatedcv", 
                       number = 2, 
                       repeats = 1, 
                       verboseIter = TRUE,
                       classProbs = TRUE,
                       returnResamp = "final",
                       summaryFunction = twoClassSummary)
  
  ranger_model &lt;- caret::train(class ~ .,
                                df,
                                method = "ranger",
                                trControl = CTRL,
                                preProc = c("center", "scale"),
                                metric="ROC",
                                tuneGrid = expand.grid(.mtry=c(1,2)))
  
  rf_model &lt;- caret::train(class ~ .,
                                df,
                                method = "rf",
                                trControl = CTRL,
                                preProc = c("center", "scale"),
                                metric="ROC",
                                tuneGrid = expand.grid(.mtry=c(1,2)))
  
  ranger_model
  rf_model
  </code></pre>
  
  <p>Ranger Output:</p>
  
  <pre><code>+ Fold1.Rep1: mtry=1 
  model fit failed for Fold1.Rep1: mtry=1 Error in parse.formula(formula, data) : 
  Error: Illegal column names in formula interface. Fix column names or use alternative interface in ranger.
  </code></pre>
  
  <p>Also, when I check the documentation for ranger that produces the error, I'm not understanding why this evaluates to TRUE, because when I run the code on my DF, I don't get the same result:</p>
  
  <pre><code>## Error if illegal column name
  if (!all(make.names(independent_vars[!interaction_idx]) == independent_vars[!interaction_idx])) {
  stop("Error: Illegal column names in formula interface. Fix column names or use alternative interface in ranger.")
  }
  </code></pre>
  
  <p><a href="https://github.com/cran/ranger/blob/master/R/formula.R" rel="nofollow noreferrer">https://github.com/cran/ranger/blob/master/R/formula.R</a></p>
  
  <p>When I run it on my df:</p>
  
  <pre><code>formula &lt;- 'class ~ .'
  data &lt;- df
  
  f &lt;- as.formula(formula)
  t &lt;- terms(f, data = data)
  
  ## Get dependent var(s)
  response &lt;- data.frame(eval(f[[2]], envir = data))
  colnames(response) &lt;- deparse(f[[2]])
  
  ## Get independent vars
  independent_vars &lt;- attr(t, "term.labels")
  interaction_idx &lt;- grepl(":", independent_vars)
  
  ## Error if illegal column name
  if (!all(make.names(independent_vars[!interaction_idx]) == independent_vars[!interaction_idx])) {
      print("Error: Illegal column names in formula interface. Fix column names or use alternative interface in ranger.")
  }
  
  &gt; !all(make.names(independent_vars[!interaction_idx]) == independent_vars[!interaction_idx])
  ## [1] FALSE
  </code></pre>
  
  <p>Is it because the factor columns are made into a 1-hot encoded matrix that uses the factor level as the column name? Again, not sure why it would work in RF and not ranger.</p>
  
  <p>Thoughts?</p>