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

arrange() drops groups when variable is specified #605

Closed
wch opened this issue Sep 17, 2014 · 4 comments
Closed

arrange() drops groups when variable is specified #605

wch opened this issue Sep 17, 2014 · 4 comments
Assignees
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@wch
Copy link
Member

wch commented Sep 17, 2014

arrange() drops groups, but only when a variable is specified.

dat <- data.frame(x = 4:1, g = c('b','b','a','a'))

# Keeps group
dat %>% group_by(g) %>% arrange()
# Source: local data frame [4 x 2]
# Groups: g
# 
#   x g
#1 2 a
#2 1 a
#3 4 b
#4 3 b

# Drops group
dat %>% group_by(g) %>% arrange(x)
# Source: local data frame [4 x 2]
# 
#   x g
#1 1 a
#2 2 a
#3 3 b
#4 4 b

I'm not sure what the expected behavior is... to me, it makes sense not to drop groups in either case.

@wch
Copy link
Member Author

wch commented Sep 17, 2014

Some tests (if grouping is to be preserved):

dat <- data.frame(x = 4:1, g = c('b','b','a','a'), g2 = c('d','c','d','c'))

expect_identical(
  dat %>% group_by(g) %>% arrange() %>% groups(),
  list(quote(g))
)
expect_identical(
  dat %>% group_by(g) %>% arrange(x) %>% groups(),
  list(quote(g))
)
expect_identical(
  dat %>% group_by(g, g2) %>% arrange() %>% groups(),
  list(quote(g), quote(g2))
)
expect_identical(
  dat %>% group_by(g2) %>% arrange(x) %>% groups(),
  list(quote(g), quote(g2))
)

@hadley hadley added the bug an unexpected problem or unintended behavior label Sep 22, 2014
@hadley hadley added this to the 0.3 milestone Sep 22, 2014
@hadley hadley self-assigned this Sep 22, 2014
@zzawadz
Copy link

zzawadz commented Sep 22, 2014

I think that this problem was introduced in be7b35c commit. Prior commit (aaf287b) works correctly. (I used example from rstudio/ggvis#166)

Maybe this information will help.

@hadley hadley assigned romainfrancois and unassigned hadley Sep 22, 2014
@hadley
Copy link
Member

hadley commented Sep 22, 2014

@romainfrancois Can you take a look at this regression please?

@romainfrancois
Copy link
Member

Done. I've put in place some tests about the structure of the created object, to make sure the grouping is done correctly. Think of anything else ?

@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
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants