title: How to specify variable filename in fread
body: <p>I have an R script that reads in several text files into data.tables. I use a for loop to step through the filelist to read in each file, which works quite well.</p>
  
  <pre><code>dta &lt;- data.table()
  for (fname in flist) {
    dt &lt;- data.table(read.csv(fname, header=T, sep=",", comment.char="#"))
    dt$FNAME &lt;- fname
    dta &lt;-rbind(dta,dt)
  }
  </code></pre>
  
  <p>In order to speed things up, I decided to try using the fread method from the data.table package. I also decided to use the grep shell command to help the operation,</p>
  
  <pre><code>dta &lt;- data.table()
  for (fname in flist) {
    dt &lt;- fread('grep RDIST fname', header=F, sep=",")
    dt$FNAME &lt;- fname
    dta &lt;-rbind(dta,dt)
  }
  </code></pre>
  
  <p>But I get an error message,</p>
  
  <pre><code>grep: fname: No such file or directory
  Error in fread("grep RDIST fname", header = F, sep = ",") :
    File is empty: /dev/shm/file2e7efc79ba710d
  </code></pre>
  
  <p>I figured that the problem is the fread command does not parse the fname variable to the actual filename. If I try to use the actual filename instead of the variable this works nicely,</p>
  
  <pre><code>&gt; fname
  [1] "QualM_Setall_20150901_165011.txt"
  &gt; dt &lt;- fread('grep RDIST QualM_Setall_20150901_165011.txt', sep=',', header=F)
  Read 4849664 rows and 15 (of 15) columns from 0.283 GB file in 00:00:04
  &gt;
  </code></pre>
  
  <p>Is there any way for me to use fname as a variable inside the shell command for fread ?</p>
  
  <p>Thanks &amp; regards,</p>
  
  <p>Derric</p>