title: Mutating column in `dplyr` using `rowSums`
body: <p>Recently I stumbled uppon a strange behaviour of <code>dplyr</code> and I would be happy if somebody would provide some insights.</p>
  
  <p>Assuming I have a data of which com columns contain some numerical values. In an easy scenario I would like to compute <code>rowSums</code>. Although there are many ways to do it, here are two examples:</p>
  
  <pre><code>df &lt;- data.frame(matrix(rnorm(20), 10, 2),
                   ids = paste("i", 1:20, sep = ""),
                   stringsAsFactors = FALSE)
  
  # works
  dplyr::select(df, - ids) %&gt;% {rowSums(.)}
  
  # does not work
  # Error: invalid argument to unary operator
  df %&gt;%
    dplyr::mutate(blubb = dplyr::select(df, - ids) %&gt;% {rowSums(.)})
  
  # does not work
  # Error: invalid argument to unary operator
  df %&gt;%
    dplyr::mutate(blubb = dplyr::select(., - ids) %&gt;% {rowSums(.)})
  
  # workaround:
  tmp &lt;- dplyr::select(df, - ids) %&gt;% {rowSums(.)}
  df %&gt;%
    dplyr::mutate(blubb = tmp)
  
  # works
  rowSums(dplyr::select(df, - ids))
  
  # does not work
  # Error: invalid argument to unary operator
  df %&gt;%
    dplyr::mutate(blubb = rowSums(dplyr::select(df, - ids)))
  
  # workaround
  tmp &lt;- rowSums(dplyr::select(df, - ids))
  df %&gt;%
    dplyr::mutate(blubb = tmp)
  </code></pre>
  
  <p>First, I don't really understand what is causing the error and second I would like to know how to actually achieve a tidy computation of some (viable) columns in a tidy way.</p>
  
  <p><em>edit</em></p>
  
  <p>The question <a href="https://stackoverflow.com/questions/33314971/mutate-and-rowsums-exclude-columns">mutate and rowSums exclude columns</a> , although related, focuses on using <code>rowSums</code> for computation. Here I'm eager to understand why the upper examples do not work. It is not so much about how to solve (see the workarounds) but to understand what happens when the naive approach is applied.</p>