title: How to extract / subset an element from a list with the magrittr %>% pipe?
body: <p>Since the introduction of the <code>%&gt;%</code> operator in the <code>magrittr</code> package (and it's use in <code>dplyr</code>), I have started to use this in my own work.</p>
  
  <p>One simple operation has me stumped, however.  Specifically, this is the extraction (or subsetting) of elements from a list.</p>
  
  <p>An example: In base R I would use <code>$</code>, <code>[</code> or <code>[[</code> to extract an element from a list:</p>
  
  <pre><code>iris$Species
  iris[["Species"]]
  </code></pre>
  
  <p>I can achieve the same using the <code>%&gt;%</code> pipe:</p>
  
  <pre><code>iris %&gt;%
    subset(select = "Species") %&gt;%
    head
  
    Species
  1  setosa
  2  setosa
  3  setosa
  4  setosa
  5  setosa
  6  setosa
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>iris %&gt;%
    `[[`("Species") %&gt;%
    levels
  
  [1] "setosa"     "versicolor" "virginica" 
  </code></pre>
  
  <p>However, this feels like a messy, clunky solution.</p>
  
  <p><strong>Is there a more elegant, canonical way to extract an element from a list using the <code>%&gt;%</code> pipe?</strong></p>
  
  <p>Note: I don't want any solution involving <code>dplyr</code>, for the simple reason that I want the solution to work with any R object, including lists and matrices, not just data frames.</p>