title: Error when trying to write to CSV with a variable in the file name (but no error if don't use function)
body: <p>I created a function <code>clean_to_CSV(df)</code> that takes in a data frame, cleans it, spits it back out, and also writes it to a CSV, with the CSV's filename using the inputted name of the dataset:</p>
  
  <pre><code>clean_to_CSV &lt;- function(df) {
      # df &lt;- # code that cleans the df (runs with no errors)
      write.csv(df, file = paste0(deparse(substitute(df)), "_clean.csv"),  row.names = FALSE)
      df
  }
  </code></pre>
  
  <p>However, this returns:</p>
  
  <pre><code>Error in file(file, ifelse(append, "a", "w")) : 
  invalid 'description' argument
  In addition: Warning messages:
  3: In if (file == "") file &lt;- stdout() else if (is.character(file)) { :
  the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  
  <p>This is very puzzling because 1) taking the <strong>exact same</strong> write.csv... line and running it <strong>outside</strong> the function works perfectly. Also, I know that writing to CSV and returning the df don't interfere with each other. Finally, I did look at related SO posts, but they were either more complex questions or didn't have a solid answer. None were such a simple case where one line of code works outside a function but not inside it.</p>