title: How do I set the upper range mtry tuning value in mlr3, when I also conduct automated feature selection?
body: <p>Date: 2022-08-17. R Version: 4.0.3. Platform: x86_64-apple-darwin17.0 (64-bit)</p>
  <p>Problem: In mlr3 (classif.task, learner: random forest), I use automated hyperparameter optimization (HPO; mtry in the range between 1 and the number of features in the data), and automated feature selection (single criterion: msr = classif.auc).</p>
  <p>I run into this ranger error message:
  'mtry can not be larger than number of variables in data. Ranger will EXIT now.'
  I am relatively sure that what happens is when a subset of features have been selected and HPO attempts to assess the performance for a higher number of features, that this produces the error. If this is true, then how do I set the upper range limit in HPO for the mtry parameter in such a case (see repex below)?</p>
  <pre><code># Make data with binary outcome.
  set.seed(123); n &lt;- 500
  for(i in 1:9) {
      assign(paste0(&quot;x&quot;, i), rnorm(n=n, mean = 0, sd = sample(1:6,1)))
  }
  z &lt;- 0 + (.02*x1) + .03*x2 - .06*x3 + .03*x4 + .1*x5 + .08*x6 + .09*x7 - .008*x8 + .045*x9
  pr = 1/(1+exp(-z))
  y = rbinom(n, 1, pr)
  dat &lt;- data.frame(y=factor(y), x1, x2, x3, x4, x5, x6, x7, x8, x9)
  # 
  library(mlr3verse)
  tskclassif &lt;- TaskClassif$new(id=&quot;rangerCheck&quot;, backend=dat, target=&quot;y&quot;)
  randomForest &lt;- lrn(&quot;classif.ranger&quot;, predict_type = &quot;prob&quot;)
  # Question: How do I set the upper range limit for the mtry parameter, in order to not get the error message?
  searchSpaceRANDOMFOREST &lt;- ps(mtry=p_int(lower = 1, upper = (ncol(dat)-1)))
  # Hyperparameter optimization
  resamplingTuner &lt;- rsmp(&quot;cv&quot;, folds=4)
  tuner &lt;- 
  atRANDOMFOREST &lt;- AutoTuner$new(
      learner=randomForest,
      resampling = resamplingTuner,
      measure = msr(&quot;classif.auc&quot;),
      search_space = searchSpaceRANDOMFOREST,
      terminator = trm(&quot;evals&quot;, n_evals = 10),
      tuner = tnr(&quot;random_search&quot;))
  # Feature selection
  instance = FSelectInstanceSingleCrit$new(
      task = tskclassif,
      learner = atRANDOMFOREST,
      resampling = rsmp(&quot;holdout&quot;, ratio = .8),
      measure = msr(&quot;classif.auc&quot;),
      terminator = trm(&quot;evals&quot;, n_evals = 20)
  )
  fselector &lt;- fs(&quot;random_search&quot;)
  fselector$optimize(instance)
  # Error message:
  # Error: mtry can not be larger than number of variables in data. Ranger will EXIT now.
  # Fehler in ranger::ranger(dependent.variable.name = task$target_names, data = task$data(),  : User interrupt or internal error.
  # This happened PipeOp classif.ranger.tuned's $train()
  </code></pre>