title: how to get name of data.frame from list passed to function using lapply
body: <p>I have function which I want to extend with ability to save results to csv file. The name of csv file should be generated based on data.frame name passed to this function:</p>
  
  <pre><code>my.func1 &lt;- function(dframe, ...){
    # PART OF CODE RESPONSIBLE FOR COMPUTATION
    # ...
  
    # PART OF CODE WHERE I WANT TO STORE RESULTS AS CSV
    csv &lt;- deparse(substitute(dframe))
    csv
  }
  </code></pre>
  
  <p>When I call this function following way then the name of dataset passed to this function is interpreted correctly:</p>
  
  <pre><code>&gt; my.func1(mtcars)
  [1] "mtcars"
  </code></pre>
  
  <p>But I need to call this function for each data.frame from list. If I call this function for particular data.frame from list then it is basically working (I get the ugly name containing also name of list but one workaround could be trim it using regular expression):</p>
  
  <pre><code>&gt; LoDFs &lt;- list(first=data.frame(y1=c(1,2,3), y2=c(4,5,6)), second=data.frame(yA=c(1,2,3), yB=c(4,5,6)))
  &gt; my.func1(LoDFs$first)
  [1] "LoDFs$first"
  </code></pre>
  
  <p>Problem is when I want to call this function for all data.frames from list. In this case the names of data.frame are mess:</p>
  
  <pre><code>&gt; lapply(LoDFs, my.func1)
  $first
  [1] "X[[i]]"
  
  $second
  [1] "X[[i]]"
  
  &gt; lapply(seq_along(LoDFs), function(x) { my.func1(LoDFs[[x]]) })
  [[1]]
  [1] "LoDFs[[x]]"
  
  [[2]]
  [1] "LoDFs[[x]]"
  </code></pre>
  
  <p>What I'm doing wrong and how can I avoid mentioned workaround with regular expressions and make code more robust?</p>