title: How to place string within write.csv argument in user-defined function
body: <p>I'm still learning the ropes of R. I have a question about using the <code>write.csv</code> function in a user-defined function to create uniquely named exportable csvs.</p>
  
  <p>For example:</p>
  
  <pre><code>pie_final &lt;- function(num_animal) {
    anim_prac &lt;- animal[num_animal]
    out_anim &lt;- capture.output(anim_prac)
    out_final_calc &lt;- as.character(strsplit(out_anim, " ")[[1]][2]) 
    samp_anim &lt;- registry[(registry$Animal == anim_prac),]
    out_final_calc
  }
  
  pie_final_2 &lt;- function(num_animal) {
    anim_prac_2 &lt;- animal[num_animal]
    out_anim_2 &lt;- capture.output(anim_prac_2)
    out_final_calc_2 &lt;- as.character(strsplit(out_anim_2, " ")[[1]][2]) 
    samp_anim_2 &lt;- registry[(registry$Animal == anim_prac_2),]
    samp_dis
  }
  
  csv_name &lt;- function(x){
    (write.csv(
      do.call(
        "&lt;-", 
        list(pie_final(x), pie_final_2(x))
      ), 
      cat(sprintf("file=\"%s.csv\"", pie_final(x)))
    ))
  }  
  </code></pre>
  
  <p>The first two functions work correctly. However, I'm hoping that the <code>csv_name</code> function will output a written csv file using the <code>write.csv</code> function with a unique name each time. For example, I am hoping the <code>file = argument</code> in the <code>write.csv</code> function will print <code>pie_final(x)</code> (which is a string) followed by <code>.csv</code>.</p>
  
  <p>When I run the function, I get the following error. </p>
  
  <pre><code>file="Falcon.csv"
  Error in if (file == "") file &lt;- stdout() else if (is.character(file)) { : argument is of length zero 
  </code></pre>
  
  <p>So, it seems like the second argument for the <code>write.csv</code> function is being produced (<code>file = "Falcon.csv"</code>), but it doesn't seem to be inserted correctly to execute the entire <code>write.csv</code> function.</p>
  
  <p>My ultimate goal is to have the final function produce uniquely-named exportable csv files.</p>
  
  <p>Do you know how to get around this issue?</p>