title: Suppress output from attr() in function result
body: <p>In the source code for <code>data.frame</code>, the last three lines of code set the attributes and return the result.</p>
  
  <pre><code>    ...
      attr(value, "row.names") &lt;- row.names
      attr(value, "class") &lt;- "data.frame"
      value
  }
  </code></pre>
  
  <p>In a function I wrote, the result is a named list created by <code>lapply</code>. Before I set any attributes in the function body, result is as follows.</p>
  
  <pre><code>&gt; x &lt;- data.frame(a = 1:5, b = letters[1:5])    
  &gt; (g &lt;- grep.dataframe("a|c", x))
  # ...    
  # $b
  #   value row
  # 1     a   1
  # 2     c   3
  &gt; attributes(g)  # I want "list" in here...
  # $names
  # [1] "a" "b"
  </code></pre>
  
  <p>I'd like "class" to be included in the attributes list, so I add <code>attr(res, "class") &lt;- "list"</code> (<code>res</code> is the final result) just before <code>res</code>. "class" now shows up in the attributes list. However,it also prints out with the result of the function, which I don't want.  I tried wrapping it with <code>invisible</code>, but that didn't work.  </p>
  
  <p>Why do the manually assigned attributes print with the function result, but are suppressed in a new data frame I create?</p>
  
  <pre><code>&gt; (h &lt;- grep.dataframe("a|c", x))
  # ...    
  # $b
  #   value row
  # 1     a   1
  # 2     c   3
  
  # attr(,"class")  # ...This prints with the result. I don't want that.
  # [1] "list"
  &gt; attributes(h)   # ...But I want these attributes
  # $names
  # [1] "a" "b"
  
  # $class
  # [1] "list"
  </code></pre>