title: auto.arima with xreg does not work within do.call
body: <p>I am using <code>auto.arima</code> with <code>xreg</code> and <code>do.call</code>. I have realized that for some time series it works well, but for some others it produces the following error which I couldn't solve:</p>
  
  <p><em>Error in dimnames(x) &lt;- dn : 
  length of 'dimnames' [2] not equal to array extent</em></p>
  
  <p>Here is a reproducible case:</p>
  
  <pre><code># packages needed
  require(magrittr)
  require(forecast) # version 8.5
  
  # create argument list
  args=list()
  args$y&lt;-ts(c(100:140,rep(200,4),380,250),start=c(2016,1),frequency = 52)
  args$seasonal&lt;-F
  args$xreg&lt;-(diag(length(args$y))%&gt;%.[,-c(1:24)])
  
  # this works well
  fit1&lt;-auto.arima(y=args$y,seasonal=args$seasonal,xreg=args$xreg)
  
  # but this does NOT work, although everything is the same!
  fit2&lt;-do.call(auto.arima,args)
  
  # however, if we change arguments slightly, do.call works well, as seen below:
  args$y&lt;-ts(10:20,start=c(2016,1),frequency = 52)
  args$xreg&lt;-(diag(length(args$y))%&gt;%.[,-c(1:4)])
  
  fit2&lt;-do.call(auto.arima,args)
  </code></pre>
  
  <p>I don't know where the problem is, auto.arima or do.call function.</p>
  
  <p>Edit: I use auto.arima within a function which takes auto.arima arguments as <code>...</code>. In other words, I don't know exactly which arguments will be supplied beforehand. A working answer should work for the following code:</p>
  
  <pre><code>foo&lt;-function(vec_ts,...){
  
    args = list(...)
    args$y&lt;-vec_ts # time series vector
  
    fit&lt;-do.call(auto.arima,args)
  
  }
  </code></pre>
  
  <p><code>...</code> may or may not include xreg. Without xreg, the function above works like a charm. But when <code>...</code> includes xreg matrix, it <em>sometimes</em> doesn't work (not always).</p>