title: n() acting inconsistently when used in summarise_at()
body: <p>Using this example data:</p>
  
  <pre><code>library(tidyverse)
  
  set.seed(123)
  df &lt;- data_frame(X1 = rep(LETTERS[1:4], 6),
                   X2 = sort(rep(1:6, 4)),
                   ref = sample(1:50, 24),
                   sampl1 = sample(1:50, 24),
                   var2 = sample(1:50, 24),
                   meas3 = sample(1:50, 24))
  </code></pre>
  
  <p>I can use <code>summarise_at()</code> to count the number of values in a subset of columns:</p>
  
  <pre><code>df %&gt;% summarise_at(vars(contains("2")), funs(sd_expr = n() ))
  </code></pre>
  
  <p>This isn't very exciting as it is the same as the number of rows. However it would be useful in a table with a nested column with each cell containing a data frame with a differing number of rows in each cell.</p>
  
  <p>For example, </p>
  
  <pre><code>df %&gt;% 
    mutate_at(vars(-one_of(c("X1", "X2", "ref"))), funs(first = . - ref)) %&gt;% 
    mutate_at(vars(contains("first")),  funs(second = . *2 )) %&gt;%
    nest(-X1) %&gt;%  
    mutate(mean = map(data, 
                    ~ summarise_at(.x, vars(contains("second")),
                                       funs(mean_second = mean(.) ))),
           n = map(data, 
                    ~ summarise_at(.x, vars(contains("second")),
                                       funs(n_second = n()  ))) ) %&gt;%
    unnest(mean, n)
  </code></pre>
  
  <p>However I get the error:</p>
  
  <blockquote>
    <p>Error in mutate_impl(.data, dots) :    Evaluation error: Can't create
    call to non-callable object.</p>
  </blockquote>
  
  <p>Why does the <code>mean()</code> function work in this context and <code>n()</code> does not?</p>
  
  <p>Now a couple of work arounds could be either:</p>
  
  <pre><code>n = map(data, ~ summarise_at(.x, vars(contains("second")),    
                                   funs(n_second = length(unique(.))  )))
  </code></pre>
  
  <p>but this is not robust to when there are identical values on different rows or alternatively:</p>
  
  <pre><code>n = map(data, ~ nrow(.x)  )
  </code></pre>
  
  <p>but this does not allow me to build more complicated <code>summarise_at()</code> functions which is what I'm really aiming for. Ultimately I'd like to do something like this to calculate standard errors:</p>
  
  <pre><code>se = map(data, ~ summarise_at(.x, vars(contains("second")),
                                           funs(se_second = sd(.)/sqrt(n())  ))) 
  </code></pre>
  
  <p>Why is <code>n()</code> not doing what I think it should do in this situation?</p>