title: Generating plots and saving automatically in R
body: <p>I created a list of title names and then modified a function i found <a href="http://www.r-bloggers.com/automatically-save-your-plots-to-a-folder/" rel="nofollow noreferrer"> here</a></p>
  <pre><code>mcollist&lt;-list(A,B,C,D)# where A,B,C and D are dataframes
  namelist&lt;-c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;)
  for(i in 1:length(namelist)){
  
  mypath &lt;- file.path(&quot;C:&quot;,&quot;Users&quot;,&quot;myname&quot;,&quot;Desktop&quot;,&quot;PLOTS&quot;,paste(&quot;myplot_&quot;, namelist[i], &quot;.jpeg&quot;, sep = &quot;&quot;))
    
    jpeg(file=mypath)
    mytitle = paste(&quot;my title is&quot;, namelist[i])
    multicolplot&lt;-lapply(mcollist,function(data){pairs(data)})##this is a function that is creating multicollinearity plot for multiple 
    ##datasets stored as a list in 'mcollist'. 
    dev.off()
  }
  </code></pre>
  <p>While I get the &quot;number of plots&quot; correct i.e. as many as the names in the list i created. The plots are all of the same dataset. I don't get any error so I'm not sure where the issue is here</p>
  <p>The same plot that is being saved multiple times is the last one on which multicolplot function is running on.</p>
  <h1>EDIT</h1>
  <p>The same function when applied to save Correlogram, won't work</p>
  <pre><code>    for(i in 1:length(data1)){
    
    
    mypath &lt;- file.path(&quot;C:&quot;,&quot;Users&quot;,&quot;myname&quot;,&quot;Desktop&quot;,&quot;PLOTS&quot;,paste(&quot;myplot_&quot;, data1[i], &quot;.jpeg&quot;, sep = &quot;&quot;))
    
    
    jpeg(file=mypath)
    mytitle = paste(&quot;Correlogram for&quot;, data1[i])
  {
      a`cf(data1[,i],na.action=na.pass,main=paste(names(data1)[i]))`
    }
  dev.off()
  }
  </code></pre>
  <p>Data1 is a dataframe containing variables (as columns) on which I wish to run acf test as implemented by the following code:</p>
  <pre><code>acf(data1[,i],na.action=na.pass,main=paste(names(data1)[i]))
  </code></pre>
  <p>It is running acf on each column of data1 ignoring 'na' values and then pasting the names from data1 column names</p>
  <p>I get the following error:</p>
  <pre><code>    Error in jpeg(file = mypath) : unable to start jpeg() device
  In addition: Warning messages:
  1: In jpeg(file = mypath) :
    unable to open file 'C:/Users/myname/Desktop/PLOTS/myplot_c(0.62, 1.13, 2.53, -0.97, 0.82, 3.9, 1.77, -0.85, 2.57, -1.1, 1.67, 1.38, 0.67, 2.73, 1.32, 0.84, 0.65, 0.96, -0.86, 0.97, 0.7, 1.05, -0.26, 0.04, 1.14, 1.46, 2.08, 1.2, 2.53, 2.49, 2.79, 2.16, 2.3, -1.29, 0.49, -1.28, 1.78, 1.26, -1.71, -3.89, 1.45, 2.2, 2.26, 1.13, 2.82, 0.83, -0.91, -0.02, 0.79, 0.71, 0, 1.37, 2.81).jpeg' for writing
  2: In jpeg(file = mypath) : opening device failed
  </code></pre>
  <p>Thanks for your help</p>