title: R: using ranger with caret, tuneGrid argument
body: <p>I'm using the <a href="https://cran.r-project.org/web/packages/caret/index.html" rel="noreferrer">caret</a> package to analyse Random Forest models built using <a href="https://cran.r-project.org/web/packages/ranger/index.html" rel="noreferrer">ranger</a>. I can't figure out how to call the train function using the tuneGrid argument to tune the model parameters.</p>
  
  <p>I think I'm calling the tuneGrid argument wrong, but can't figure out why it's wrong. Any help would be appreciated.</p>
  
  <pre><code>data(iris)
  
  library(ranger)
  model_ranger &lt;- ranger(Species ~ ., data = iris, num.trees = 500, mtry = 4,
                         importance = 'impurity')
  
  
  library(caret)
  
  # my tuneGrid object:
  tgrid &lt;- expand.grid(
    num.trees = c(200, 500, 1000),
    mtry = 2:4
  )
  
  model_caret &lt;- train(Species  ~ ., data = iris,
                       method = "ranger",
                       trControl = trainControl(method="cv", number = 5, verboseIter = T, classProbs = T),
                       tuneGrid = tgrid,
                       importance = 'impurity'
  )
  </code></pre>