title: combining ldply to combine multiple csv files AND add column with file names via mutate/basename
body: <p>I'm trying to apply the code here <a href="https://stackoverflow.com/questions/40063507/how-to-loop-through-a-folder-of-csv-files-in-r">which uses ldply to combine multiple csv files into one dataframe</a></p>
  
  <p>I'm trying to figure out what the appropriate <code>tidyverse</code> syntax is to add a column that lists the name of the file from which the data comes from.</p>
  
  <p>Here's what I have</p>
  
  <pre><code>test &lt;- ldply( .data = list.files(pattern="*.csv"),
                .fun = read.csv,
                 header = TRUE) %&gt;%
    mutate(filename=gsub(".csv","",basename(x)))
  </code></pre>
  
  <p>I get </p>
  
  <blockquote>
    <p>"Error in basename(x) : object 'x' not found message". </p>
  </blockquote>
  
  <p>My understanding is that basename(path), but when I set the path as the folder which contains the file, the filename column that ends up getting added just has the folder name.</p>
  
  <p>Any help is much appreciated!</p>