Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HAVING for summarise() + filter() #877

Merged
merged 12 commits into from
Jul 31, 2022
Merged

Use HAVING for summarise() + filter() #877

merged 12 commits into from
Jul 31, 2022

Conversation

mgirlich
Copy link
Collaborator

This solves the first of two cases where HAVING can be used according to #870.

library(dplyr, warn.conflicts = FALSE)
library(dbplyr, warn.conflicts = FALSE)

lazy_frame(g = 1, x = 1, y = 1) %>% 
  group_by(g) %>% 
  summarise(x_mean = mean(x, na.rm = TRUE)) %>% 
  filter(x_mean > 1, g == 1)

Before

SELECT *
FROM (
  SELECT `g`, AVG(`x`) AS `x_mean`
  FROM `df`
  GROUP BY `g`
) `q01`
WHERE (`x_mean` > 1.0) AND (`g` = 1.0)

After

SELECT `g`, AVG(`x`) AS `x_mean`
FROM `df`
GROUP BY `g`
HAVING (AVG(`x`) > 1.0) AND (`g` = 1.0)

@mgirlich mgirlich added this to the 2.3.0 milestone May 18, 2022
Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great!

R/tidyeval.R Outdated Show resolved Hide resolved
tests/testthat/_snaps/verb-filter.md Outdated Show resolved Hide resolved
@mgirlich mgirlich merged commit eac9c61 into main Jul 31, 2022
@mgirlich mgirlich deleted the having branch July 31, 2022 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants