title: Read multiple .txt files and add new column identifying file name in R
body: <p>I have 1500+ .txt files called data_{date from 2015070918 to today} all with 7 columns worth of data and variable row amounts.  I have managed to use the following code to extract and merge the data into one table:</p>
  
  <pre><code>files = list.files(pattern = ".txt")
  myData &lt;- lapply(files, function(x) {
  tryCatch(read.table(x, header = F, sep = ','), error=function(e) NULL)
  })
  </code></pre>
  
  <p>Note: there are no headers on the columns, currently I don't even know which variable is which!</p>
  
  <p>At the moment the data only has the date in the file name and therefore it isn't possible to distinguish between each subset of daily data.  I want to create an additional column to include the date which I can extract if I can include the filename in an additional column.  </p>
  
  <p>I searched on stackexchange and came across this possible solution: <a href="https://stackoverflow.com/questions/41006985/importing-multiple-csv-files-into-r-and-adding-a-new-column-with-file-name">Importing multiple .csv files into R and adding a new column with file name</a></p>
  
  <pre><code>df &lt;- do.call(rbind, lapply(files, function(x) cbind(read.csv(x, header = F, sep = ","), name=strsplit(x,'\\.')[[1]][1])))
  </code></pre>
  
  <p>However I get the following error:</p>
  
  <pre><code> Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
   no lines available in input 
  </code></pre>
  
  <p>I have used read.csv on individual files and they have imported without any issues.  Any ideas to resolve this would be greatly appreciated!</p>