title: How to use a character value when using the 'model' function to call the model/variable to forecast?
body: <p>My aim is to make a function where you input the variable you want forecasted, and then use cross validation on multiple types of models (ie. Naive, ETS, Mean), then using the 'pull' function I will pull out the model with the lowest RMSE, then I will forecast 1 step ahead with the best model.</p>
  <p>However, I am having trouble with the second last line, using the character value 'best.model' as the input for the model when forecasting. (Error is below the code, which you an run yourself).</p>
  <p>Here is the code to make more sense:</p>
  <pre><code>library(fpp3)
  tsibble &lt;- prices
  
  function.fc &lt;- function (variable) {
  
  ## cross validation models
  cv.fit &lt;- tsibble %&gt;%
    select(year, !!sym(variable)) %&gt;%
    stretch_tsibble(.init = 180, .step = 1) %&gt;%
    filter(.id != max(.id)) %&gt;%
    model(
      MEAN(!!sym(variable)),
      NAIVE(!!sym(variable))
    ) 
  
  ## cv forecasts
  cv.fc &lt;- cv.fit %&gt;%
    forecast(h = 1)
  
  ## cv accuracy
  cv.accuracy &lt;- cv.fc %&gt;%
    accuracy(tsibble)
  
  ## pulls out the name of the best model
  best.model &lt;- cv.accuracy %&gt;%
    select(.model, .type, RMSE) %&gt;%
    arrange(RMSE) %&gt;%
    filter(row_number(RMSE) == 1) %&gt;%
    pull(.model)
  
  ## pulls out 1 step forecast 
  fc &lt;- model(.data = tsibble, noquote(best.model)) %&gt;%
    forecast(h = 1)
  
  
  return(fc)
  
  }
  
  
  function.fc(&quot;copper&quot;)
  
  Error: Model definition(s) incorrectly created: noquote(best.model) Check that specified model(s) are model definitions. Run `rlang::last_error()` to see where the error occurred
  </code></pre>
  <p>As you can see I have tried using the 'unquote' function but this still does not work.
  Does anyone have any suggestions on what to use? I have struggled to find other posts with my problem.</p>