title: rmse function issue in R
body: <p>I have an <code>R</code> code that contains some nested bracket for loop within which I used <code>rmse()</code> function from <code>Metrics</code> package. I tried it without the function and it worked, but inside my nested <code>R</code> code it does not.</p>
  
  <p><strong>Here is what I desire to do with <code>R</code></strong></p>
  
  <ol>
  <li>I have generated a 50-time series dataset.</li>
  <li>I lice the same time series dataset into chunks of the following sizes: <code>2,3,...,48,49</code> making me have 48 different time series formed from step 1 above.</li>
  <li>I divided each 48-time series dataset into <code>train</code> and <code>test</code> sets so I can use <code>rmse</code> function in <code>Metrics</code> package to get the Root Mean Squared Error (RMSE) for the 48 subseries formed in step 2.</li>
  <li>The RMSE for each series is then tabulated according to their chunk sizes</li>
  <li>I obtained the best <code>ARIMA</code> model for each 48 different time series data set.</li>
  </ol>
  
  <p><strong>My R code</strong></p>
  
  <pre><code> # simulate arima(1,0,0)
   library(forecast)
   library(Metrics)
   n &lt;- 50
   phi &lt;- 0.5
   set.seed(1)
   wn &lt;- rnorm(n, mean=0, sd=1)
      ar1 &lt;- sqrt((wn[1])^2/(1-phi^2))
   for(i in 2:n){
     ar1[i] &lt;- ar1[i - 1] * phi + wn[i]
   }
   ts &lt;- ar1
  
   t&lt;-length(ts)# the length of the time series
   li &lt;- seq(n-2)+1 # vector of block sizes(i.e to be between 1 and n exclusively)
  
   RMSEblk&lt;-matrix(nrow = 1, ncol = length(li))#vector to store block means
   colnames(RMSEblk)&lt;-li
   for (b in 1:length(li)){
       l&lt;- li[b]# block size
       m &lt;- ceiling(t / l) # number of blocks
       blk&lt;-split(ts, rep(1:m, each=l, length.out = t)) # divides the series into blocks
       singleblock &lt;- vector() #initialize vector to receive result from for loop
       for(i in 1:10){
           res&lt;-sample(blk, replace=T, 100) # resamples the blocks
           res.unlist&lt;-unlist(res, use.names = F) # unlist the bootstrap series
           # Split the series into train and test set
           train &lt;- head(res.unlist, round(length(res.unlist) * 0.6))
           h &lt;- length(res.unlist) - length(train)
           test &lt;- tail(res.unlist, h)
  
          # Forecast for train set
          model &lt;- auto.arima(train)
          future &lt;- forecast(test, model=model,h=h)
          nfuture &lt;- as.numeric(out$mean) # makes the `future` object a vector
          # use the `rmse` function from `Metrics` package
          RMSE &lt;- rmse(test, nn)
          singleblock[i] &lt;- RMSE # Assign RMSE value to final result vector element i
      }
      #singleblock
      RMSEblk[b]&lt;-mean(singleblock) #store into matrix
   }
   RMSEblk
  </code></pre>
  
  <p><strong>The error I got</strong></p>
  
  <pre><code>#Error in rmse(test, nn): unused argument (nn)
  #Traceback:
  </code></pre>
  
  <p>But when I wrote </p>
  
  <pre><code>library(forecast)
  
  train &lt;- head(ar1, round(length(ar1) * 0.6))
  h &lt;- length(ar1) - length(train)
  test &lt;- tail(ar1, h)
  model &lt;- auto.arima(train)
  #forecast &lt;- predict(model, h)
  out &lt;- forecast(test, model=model,h=h)
  nn &lt;- as.numeric(out$mean)
  rmse(test, nn)
  </code></pre>
  
  <p>It did work</p>
  
  <p><strong>Please point out what I am missing?</strong></p>