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

Deleting column used in grouping should remove grouped_df attribute #2031

Closed
puzzledvacuum opened this issue Jul 21, 2016 · 2 comments
Closed

Deleting column used in grouping should remove grouped_df attribute #2031

puzzledvacuum opened this issue Jul 21, 2016 · 2 comments
Assignees
Labels
Milestone

Comments

@puzzledvacuum
Copy link

@puzzledvacuum puzzledvacuum commented Jul 21, 2016

If the user has a grouped_df and sets one of the coulumns used in the grouping to NULL this should remove the grouped_df attribute and make it a regular tbl.

Currently, if the user sets a column used as a grouping to NULL, and then tries to rename a different column, this causes the R session to abort.

Example:

df = data_frame(a = c(1,2,3), b = c(2,3,4), d = c(4,5,6))  
df = df %>% group_by(a,b)  
df$a = NULL  
class(df)
## [1] "grouped_df" "tbl_df"     "tbl"        "data.frame"
df = df %>% rename(a = d)

At this point the R session will crash.

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Nov 7, 2016

Thanks, confirmed. Would you like to contribute a testthat test?

@krlmlr krlmlr self-assigned this Feb 10, 2017
@krlmlr krlmlr added this to the data frame 2 milestone Feb 20, 2017
@krlmlr krlmlr added this to the data frame 2 milestone Feb 20, 2017
@hadley
Copy link
Member

@hadley hadley commented Feb 21, 2017

We don't need to override $ to remove the attribute, but we should throw an error rather than crashing.

@krlmlr krlmlr assigned krlmlr and unassigned krlmlr Mar 21, 2017
krlmlr added a commit to krlmlr/dplyr that referenced this issue Mar 21, 2017
@krlmlr krlmlr closed this in #2552 Mar 21, 2017
krlmlr added a commit to krlmlr/dplyr that referenced this issue Mar 21, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants