title: How to run a script for multiple inputs and save result objects based on the name of input?
body: <p>To run the same set of commands and save the result objects for each time series, I wrote the script in the following manner : </p>
  
  <pre><code># Specify time series to be used 
  
  dat &lt;- tsname
  
  # Run a set of commands and fit models with different parameters 
  dat.1 &lt;- model1(dat)
  dat.2 &lt;- model2(dat)
  dat.3 &lt;- model3(dat)
  
  # Save objects for further analysis 
  
  tsname.1 &lt;- dat.1
  tsname.2 &lt;- dat.2
  
  
  save(tsname.1, tsname.2, tsname.3, file = paste0("tsname", ".rda")
  </code></pre>
  
  <p>In this way, we just need to change the script in the beginning and end, save the script for each time series and run each of them individually or in a main script. </p>
  
  <p>The main reason for this method was because I could not find a way to rename the objects created and some search suggested that the above is the only way to do it. </p>
  
  <p>Now as the number of series has increased, it is preferable to either use a for loop, foreach, batch script or commandArgs() to run one script and specify all time series as arguments. 
  To make that work though, the script must find a way to assign these objects with name of series itself so that they can be loaded later for further analysis. </p>
  
  <p>How can we make such a script work or is there a better approach ? Which method of looping will work in that case ? </p>
  
  <p>A MWE </p>
  
  <pre><code>set.seed(1)
  tsdata &lt;- ts(rnorm(250), start = c(1980,1), frequency = 12)
  dat &lt;- tsdata
  dat.11 &lt;- arima(dat, order = c(1, 1, 1))
  dat.21 &lt;- arima(dat, order = c(2, 1, 0))
  
  tsname.11 &lt;- dat.11  # problem is to specify this step in each script
  tsname.21 &lt;- dat.21
  save(tsname.11, , file = "tsname.rda")
  </code></pre>
  
  <p><em>REVISED the code</em></p>
  
  <p>How can we execute this script for multiple time series and store the results and result objects for further analysis ? If Batch command can be used, what is the best way to input set of multiple time series?</p>
  
  <p><em>How can we run the script for one series, over a set of time series of same or mixed length?</em></p>