title: Unquote string in R's substitute command
body: <p>I'd like to know whether it is possible to <em>unquote</em> a string passed to an expression via the substitute command.</p>
  
  <p>Specifically, I am using dplyr to filter and select from a data frame:</p>
  
  <pre><code>    &gt; w
         subject sex response
      1        1   M    19.08
      2        2   M    16.46
      ...     ...  ...  ...
      6        6   M    23.60
      7        7   M    23.96
      8        8   F    22.48
      9        9   F    25.79
      ...     ...  ...  ...
      16      16   F    26.66
  </code></pre>
  
  <p>The following produces the desired result:</p>
  
  <pre><code>    &gt; w %.% filter(sex == "M") %.% select(response)        
        response
      1    19.08
      2    16.46
      3    22.81
      4    18.62
      5    18.75
      6    23.60
      7    23.96
  </code></pre>
  
  <p>But I want to do this in a more general way. Th following does not produce the required result since the string "sex" is enclosed in quotation marks.</p>
  
  <blockquote>
    <p>substitute(w %.% filter(y == "M"), list(y = paste(names(w)[2])))</p>
  </blockquote>
  
  <pre><code>    w %.% filter("sex" == "M")
      &gt; eval(substitute(w %.% filter(y == "M"), list(y = paste(names(w)[2]))))
      [1] subject  sex      response
      &lt;0 rows&gt; (or 0-length row.names)
  </code></pre>
  
  <p>I can always do the following:</p>
  
  <pre><code>    eval(parse(text = paste("w %.% filter(", names(w)[2], " == 'M')")))
  </code></pre>
  
  <p>This does, however, look a little clumsy.</p>
  
  <p>Are there more elegant ways of doing this? Eventually, I'd like to wrap this up in a function and make it even more general.</p>
  
  <p>Any help / suggestion would be much appreciated.</p>
  
  <p>Kind regards,</p>
  
  <p>Stefan</p>