title: Renaming a Summarised Column inside Redshift dplyr operations
body: <p>I am using dplyr to do certain operations in Redshift so I don't load the data in memory.</p>
  
  <pre><code>data &lt;- tbl(conn, "customers") %&gt;%
    filter(age &gt;= 18)
  subset &lt;- data %&gt;% 
    filter(eye_color != "brown") %&gt;%
    group_by(gender, method, age, region) %&gt;% 
    summarise(sum(purchases)) %&gt;%  # will create a column called sum(purchases)
    full_join(data, by=c("region", "age", "method"))
  </code></pre>
  
  <p>Right now when I look at the resulting dataframe, I will see a column called <code>sum(purchases)</code> and I want to rename it to <code>purchases</code> which will create the columns, <code>purchase.x</code> and <code>purchase.y</code> after the merge.</p>
  
  <p>Most of the renaming that I've <a href="https://blog.exploratory.io/selecting-columns-809bdd1ef615" rel="nofollow noreferrer">read</a> so far are dealing with dataframes that are in memory rather than dataframes that are lazily evaluated with dbplyr. I have tried using <code>rename</code>, <code>rename_</code>, <code>rename_at</code> as well as different variations of <code>select</code>. I have also tried strategies laid out <a href="https://stackoverflow.com/questions/45076971/changing-names-of-resulting-variables-in-custom-dplyr-function">here</a> and <a href="https://stackoverflow.com/questions/31626682/renaming-variable-column-in-r">here</a> but no luck</p>
  
  <p>Is there a way to rename the <code>sum(purchases)</code>. The only other option I have is to load the dataframe in memory at a certain step </p>
  
  <pre><code>data &lt;- tbl(conn, "customers") %&gt;%
    filter(age &gt;= 18)
  subset &lt;- data %&gt;% 
    filter(eye_color != "brown") %&gt;%
    group_by(gender, method, age, region) %&gt;% 
    summarise(sum(purchases)) %&gt;% 
  loaded &lt;- as.data.frame(subset)
  # do some join here but in memory and not in Redshift
  # full_join(data, by=c("region", "age", "method"))
  </code></pre>