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

$get_used() is relative to $current_vars(), not names(.data) #5584

Merged
merged 4 commits into from Nov 4, 2020

Conversation

romainfrancois
Copy link
Member

This does not yet deals with #5582 but there still was a little problem that attr(cols, "used") aka mask$get_used() is relative to the accumulated variables, not just names(.data).

Then, is this correct:

library(dplyr, warn.conflicts = FALSE)

iris %>%
  group_by(Species) %>%
  mutate(meanPL = mean(Petal.Length), .keep = "all") %>% 
  group_vars()
#> [1] "Species"

iris %>%
  group_by(Species) %>%
  mutate(meanPL = mean(Petal.Length), .keep = "none") %>% 
  group_vars()
#> [1] "Species"

iris %>%
  group_by(Species) %>%
  mutate(meanPL = mean(Petal.Length), .keep = "used") %>% 
  group_vars()
#> character(0)

iris %>%
  group_by(Species) %>%
  mutate(meanPL = mean(Petal.Length), .keep = "unused") %>% 
  group_vars()
#> [1] "Species"

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

@romainfrancois
Copy link
Member Author

In particular "none" re-injects the grouping variables ...

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.

Can you add a unit test please?

@romainfrancois romainfrancois merged commit df43c73 into master Nov 4, 2020
@romainfrancois romainfrancois deleted the 5582_mutate_keep branch November 4, 2020 10:39
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