title: R: Function variable not being read during sapply
body: <p>I'm back in R after a long hiatus trying to make simple tool to make my work easier and I'm stuck on what seems like a simple issue, yet I cannot find an answer elsewhere.</p>
  <p>I have a list of files in a .txt and trying to bind them to a master file after chopping off the headers for each file in the list. All files are the same format</p>
  <p>I tested a function on a single file pathway and it worked perfect. However, once I tried using <code>sapply</code> to work through my text file of pathways, I am getting the following error:</p>
  <blockquote>
  <p>Error in fread(x, skip = 10, header = TRUE, sep = &quot;,&quot;, select = c(&quot;Sample_ID&quot;,  :
  input= must be a single character string containing a file name etc etc</p>
  </blockquote>
  <p>My working function:</p>
  <pre><code># Reading in the list of files
  pathway_list &lt;- readLines(&quot;Y:/.../Pathways.txt&quot;)
  
  # Test file
  sheet &lt;- &quot;W:/.../samplesheet.csv&quot;
  
  # Function to skip header and bind imported file to master   
      testfunc &lt;- function(x) {
   
               # Create truncated file
                  file &lt;- fread(x, skip=10, header=TRUE, sep = &quot;,&quot;,
                          select = c(&quot;Sample_ID&quot;,
                                  &quot;SentrixBarcode_A&quot;,
                                  &quot;SentrixPosition_A&quot;,
                                  &quot;Sample_Plate&quot;,
                                  &quot;Sample_Well&quot;,
                                  &quot;Gender&quot;,
                                  &quot;Species&quot;)) %&gt;%
                           mutate(across(everything(), as.character))
      
               # Bind imported file (file) to the master (final)
                  final &lt;- bind_rows(final, file)
      }
  
  # Calling this function works just fine
      final &lt;- testfunc(sheet)
  </code></pre>
  <p>Encouraged, I tried using <code>sapply</code> which I had just used a few days earlier to apply a function to another list of files in a .txt. Below is when I get the error trying to run it through my list:</p>
  <pre><code>sapply(pathway_list, testfunc)
  </code></pre>
  <p>I'm just lost as to why <code>sapply</code> will read my file names from the other .txt but not this one.
  Any help is greatly appreciated!</p>