R 3.1 sapply to a list of files <p>I want to parse the <code>read.table()</code> function to a list of <em>.txt</em> files. These files are in my current directory. </p> <pre><code> my.txt.list &lt;- list("subject_test.txt", "subject_train.txt", "X_test.txt", "X_train.txt") </code></pre> <p>Before applying <code>read.table()</code> to elements of this list, I want to check if the <strong>dt</strong> has not been already computed and is in a cache directory. <strong>dt</strong> from cache directory are already in my <code>environment()</code>, in form of <em>file_name.dt</em> </p> <pre><code> R&gt; ls() "subject_test.dt" "subject_train.dt" </code></pre> <p>In this example, I only want to compute "X_test.txt" and "X_train.txt". I wrote a small function to test if <strong>dt</strong> has already been cached and apply <code>read.table()</code>in case not.</p> <pre><code> my.rt &lt;- function(x,...){ # apply read.table to txt files if data table is not already cached # x is a character vector y &lt;- strsplit(x,'.txt') y &lt;- paste(y,'.dt',sep = '') if (y %in% ls() == FALSE){ rt &lt;- read.table(x, header = F, sep = "", dec = '.') } } </code></pre> <p>This function works if I take one element this way :</p> <pre><code> subject_test.dt &lt;- my.rt('subject_test.txt') </code></pre> <p>Now I want to <code>sapply</code> to my files list this way:</p> <pre><code> my.res &lt;- saply(my.txt.list,my.rt) </code></pre> <p>I have <code>my.res</code>as a list of <strong>df</strong>, but the issue is the function compute all files and does take into account already computed files.</p> <p>I must be missing something, but I can't see why.</p> <p>TY for suggestions.</p>