title: How do I loop in a list and access both names and attributes?
body: <p>I am applying a function to the elements of a list.</p>
  
  <p>the list has <code>names</code>, so in a sense each element has its own name, but how do I access it once the <code>lapply</code> function has already extracted/separated the element from the list?</p>
  
  <p>Some fictive data (as internal function I'm here misusing <code>dput</code>):</p>
  
  <pre><code>r &lt;- list(a=structure(1:4, unit="test"), b='abc')
  lapply(r, dput)
  </code></pre>
  
  <p>What I observe here is that <code>dput</code> receives the objects in the list as if accessed with <code>[[</code>, deprived of the name they have in the containing list.</p>
  
  <p>So I thought I would drop the idea of using functions from the <code>apply</code> family and write a loop, but I don't particularly like the idea and it obliges me to construct the result of the complete function.</p>
  
  <pre><code>result &lt;- list()
  for (name in names(r)) {
    print(name)
    result[[name]] &lt;- dput(r[[name]])
  }
  result
  </code></pre>
  
  <p>Any insightful thoughts?</p>