title: Reading multiple files from a directory, R
body: <p>I am having difficulty with one step in my code to read in a folder of text files and convert it to a dtm.  The problem is that, for some reason, my computer is only able to intermittently establish a connection with the text files in the directory.  The error that returns is:</p>
  
  <pre><code>Error in file(con, "r") : cannot open the connection
  In addition: Warning message:
  In file(con, "r") :
    cannot open file '[file name]': No such file or directory
  </code></pre>
  
  <p>However, I can easily open these files in any text editor, as well as in python.  Any ideas why I might be able to establish the connection sometimes and not others?  My code is below:</p>
  
  <pre><code>files &lt;- as.character(list.files(path="[file path]"))
  readLines(files[1])  #here is where the error occurs, for example
  n &lt;- length(files) #this is my loop
  subtitles &lt;- character(n)
  subtitle &lt;- character(1)
  
  for (i in 1:n){
     subtitle &lt;- as.character(readLines(files[i]))
     subtitle &lt;- iconv(subtitle, to="UTF8")
     subtitle &lt;-  tolower(subtitle)
     subtitle &lt;- as.character(paste(subtitle, collapse=" "))
     subtitles[i] &lt;- subtitle[1]
  }
  </code></pre>