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

compute groups on ungrouped data. #5598

Merged
merged 4 commits into from Nov 10, 2020
Merged

Conversation

romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Nov 9, 2020

related to #5473

library(dplyr, warn.conflicts = FALSE)

df <- tibble(x = c(1,2), y = c(3,4), z = c(5,6))

df %>% 
  dplyr::group_by(y) %>%
  dplyr::group_by(across(any_of(c('y','z')))) %>%
  dplyr::group_vars() 
#> [1] "y" "z"

df %>% 
  dplyr::group_by(y) %>%
  dplyr::group_by(y, z) %>%
  dplyr::group_vars() 
#> [1] "y" "z"

Created on 2020-11-09 by the reprex package (v0.3.0.9001)

On master, only the second one incorporates y. Is there any reason why the implicit mutate() step uses the grouped data instead of the ungrouped data, as suggested by this PR ?

library(dplyr, warn.conflicts = FALSE)

df <- tibble(x = c(1,2), y = c(3,4), z = c(5,6))

df %>% 
  dplyr::group_by(y) %>%
  dplyr::group_by(across(any_of(c('y','z')))) %>%
  dplyr::group_vars() 
#> [1] "z"

df %>% 
  dplyr::group_by(y) %>%
  dplyr::group_by(y, z) %>%
  dplyr::group_vars() 
#> [1] "y" "z"

Created on 2020-11-09 by the reprex package (v0.3.0.9001)

I'll add some tests if this is sound.

hadley
hadley approved these changes Nov 9, 2020
Copy link
Member

@hadley hadley left a comment

Oh yeah, this is surprising! We should make sure to make this prominent in the blog post.

@romainfrancois romainfrancois mentioned this pull request Nov 10, 2020
18 tasks
@romainfrancois romainfrancois merged commit c283c9e into master Nov 10, 2020
7 of 10 checks passed
@romainfrancois romainfrancois deleted the 5473_group_by_not_add branch Nov 10, 2020
hadley pushed a commit to hadley/cubelyr that referenced this issue Nov 20, 2020
* + ungroup.tbl_cube() is needed for dplyr 1.0.3 as per tidyverse/dplyr#5598

* bump requirement to R 3.3

* update github action workflow
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.

None yet

2 participants