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

Can't use rename on grouped_df #640

Closed
hmalmedal opened this issue Sep 27, 2014 · 4 comments
Closed

Can't use rename on grouped_df #640

hmalmedal opened this issue Sep 27, 2014 · 4 comments
Labels
Milestone

Comments

@hmalmedal
Copy link

@hmalmedal hmalmedal commented Sep 27, 2014

The function rename doesn't work with grouping.

data_frame(a = 1, b = 2) %>%
  group_by(a) %>%
  rename(c = b)
## Source: local data frame [1 x 2]
## Groups: a
## 
##   a b
## 1 1 2
@hadley
Copy link
Member

@hadley hadley commented Sep 27, 2014

Yes, you can't currently modify grouping columns

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Sep 30, 2014

But b is not a grouping column here.

@romainfrancois romainfrancois added this to the 0.3 milestone Sep 30, 2014
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Sep 30, 2014

I think it was just an oversight in how rename_vars was called. Can you check @hadley and reopen the issue if my understanding of lazyeval is wrong.

BTW, the internal code for select which is used eventually does know how to handle grouping, i.e.

> res <- data_frame(a = 1, b = 2) %>% group_by(a) %>% rename(c = a)
> str(res)
Classes ‘grouped_df’, ‘tbl_df’, ‘tbl’ and 'data.frame': 1 obs. of  2 variables:
 $ c: num 1
 $ b: num 2
 - attr(*, "vars")=List of 1
  ..$ : symbol c
 - attr(*, "drop")= logi TRUE
 - attr(*, "indices")=List of 1
  ..$ : int 0
 - attr(*, "group_sizes")= int 1
 - attr(*, "biggest_group_size")= int 1
 - attr(*, "labels")='data.frame':  1 obs. of  1 variable:
  ..$ c: num 1
  ..- attr(*, "vars")=List of 1
  .. ..$ : symbol c

@hadley
Copy link
Member

@hadley hadley commented Sep 30, 2014

Ooops, yes. Thanks @romainfrancois !

@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 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.

None yet
3 participants