title: R lazyeval: pass parameters to dplyr::filter
body: <p>I think this questions has multiple other variations (eg: <a href="https://stackoverflow.com/questions/41783396/passing-arguments-to-dplyr-summarize-function?rq=1">here</a>, <a href="https://stackoverflow.com/questions/28973056/in-r-pass-column-name-as-argument-and-use-it-in-function-with-dplyrmutate-a">here</a>  and perhaps <a href="https://stackoverflow.com/questions/27197617/filter-data-frame-by-character-column-name-in-dplyr">here</a>) - probably even an answer somewhere.</p>
  
  <p>How to provide parameters to the filter function.</p>
  
  <pre><code>library(dplyr)
  library(lazyeval)
  set.seed(10)
  data &lt;- data.frame(a=sample(1:10, 100, T))
  </code></pre>
  
  <p>If I need to count the number of occurrences of the number 1 through 10 occurs and show the count for, say 1, 2 and 3, I would do this:</p>
  
  <pre><code>data %&gt;% 
    group_by(a) %&gt;% 
    summarise(n = n()) %&gt;% 
    filter(a &lt; 4)
  </code></pre>
  
  <p>Gives: </p>
  
  <pre><code># A tibble: 3 × 2
        a     n
    &lt;int&gt; &lt;int&gt;
  1     1    11
  2     2     8
  3     3    16
  </code></pre>
  
  <p>Now, how can I put this into a function ?
  Here <code>grp</code> is the grouping var. </p>
  
  <pre><code>   fun &lt;- function(d, grp, no){
        d %&gt;% 
          group_by_(grp) %&gt;% 
          summarise_(n = interp(~ n() )) %&gt;%
          filter_( grp &lt; no)
          # This final line instead also does not work:  
          # filter_(interp( grp &lt; no), grp = as.name(grp))
      }
  </code></pre>
  
  <p>Now,</p>
  
  <pre><code>fun(data, 'a', 4)
  </code></pre>
  
  <p>Gives:</p>
  
  <pre><code># A tibble: 0 × 2
  # ... with 2 variables: a &lt;int&gt;, n &lt;int&gt;
  </code></pre>