title: Loop to create and save histograms resulting in error
body: <p>I'm trying to create a block of code that will run through each file in a folder (C:/stockHistoryYear/), get the stock return values, create a histogram, and save the histogram for each file
  However, the code I am using returns with error </p>
  
  <blockquote>
    <p>Error in file(file, "rt") : cannot open the connection</p>
  </blockquote>
  
  <p>I am new to R and most of my info is from random Youtube videos and this website. I would love any assistance, and additional knowledge you may have</p>
  
  <p>My current code:</p>
  
  <pre><code>for (i in 1:length(files)) {
   data &lt;- read.csv(files[i])
   prices &lt;- data[, "Adj.Close"]
   n &lt;- NROW (prices)
   ret &lt;- ((prices[2:n]-prices[1:(n-1)])/prices[1:(n-1)])
   names(ret) &lt;- data[2:n, "Date"]
   picname &lt;- c(toString(files[i]),'.png')
   toString(picname)
   png(picname)
   hist(ret, col = "blue", lwd = 2, ylab = "Frequency", xlab = "Stock Return", 
   main = i)
   dev.off() 
  }
  </code></pre>
  
  <p>Performing traceback() resulted in:</p>
  
  <pre><code>3: file(file, "rt")
  2: read.table(file = file, header = header, sep = sep, quote = quote, 
         dec = dec, fill = fill, comment.char = comment.char, ...)
  1: read.csv(files[i])
  </code></pre>