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 ungroup using group_by() #615

Closed
davidchall opened this issue Mar 11, 2021 · 0 comments · Fixed by #616
Closed

Can't ungroup using group_by() #615

davidchall opened this issue Mar 11, 2021 · 0 comments · Fixed by #616

Comments

@davidchall
Copy link
Contributor

davidchall commented Mar 11, 2021

I found an inconsistency between dplyr and dbplyr with how grouping works.

If you have a grouped tibble and call group_by() (i.e. with no grouping variables), it should return an ungrouped tibble. This makes it easier to write functions that restore original groupings (e.g. group_by(!!!groups(.data))).

library(tidyverse)
library(dbplyr)

# ungrouped output
storms %>% group_by(status) %>% group_by()
#> # A tibble: 10,010 x 13
#>    name   year month   day  hour   lat  long status      category  wind pressure
#>    <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <chr>       <ord>    <int>    <int>
#>  1 Amy    1975     6    27     0  27.5 -79   tropical d… -1          25     1013
#>  2 Amy    1975     6    27     6  28.5 -79   tropical d… -1          25     1013
#>  3 Amy    1975     6    27    12  29.5 -79   tropical d… -1          25     1013
#>  4 Amy    1975     6    27    18  30.5 -79   tropical d… -1          25     1013
#>  5 Amy    1975     6    28     0  31.5 -78.8 tropical d… -1          25     1012
#>  6 Amy    1975     6    28     6  32.4 -78.7 tropical d… -1          25     1012
#>  7 Amy    1975     6    28    12  33.3 -78   tropical d… -1          25     1011
#>  8 Amy    1975     6    28    18  34   -77   tropical d… -1          30     1006
#>  9 Amy    1975     6    29     0  34.4 -75.8 tropical s… 0           35     1004
#> 10 Amy    1975     6    29     6  34   -74.8 tropical s… 0           40     1002
#> # … with 10,000 more rows, and 2 more variables: ts_diameter <dbl>,
#> #   hu_diameter <dbl>

# grouped output
memdb_frame(storms) %>% group_by(status) %>% group_by()
#> # Source:   lazy query [?? x 13]
#> # Database: sqlite 3.34.1 [:memory:]
#> # Groups:   status
#>    name   year month   day  hour   lat  long status      category  wind pressure
#>    <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <chr>       <chr>    <int>    <int>
#>  1 Amy    1975     6    27     0  27.5 -79   tropical d… -1          25     1013
#>  2 Amy    1975     6    27     6  28.5 -79   tropical d… -1          25     1013
#>  3 Amy    1975     6    27    12  29.5 -79   tropical d… -1          25     1013
#>  4 Amy    1975     6    27    18  30.5 -79   tropical d… -1          25     1013
#>  5 Amy    1975     6    28     0  31.5 -78.8 tropical d… -1          25     1012
#>  6 Amy    1975     6    28     6  32.4 -78.7 tropical d… -1          25     1012
#>  7 Amy    1975     6    28    12  33.3 -78   tropical d… -1          25     1011
#>  8 Amy    1975     6    28    18  34   -77   tropical d… -1          30     1006
#>  9 Amy    1975     6    29     0  34.4 -75.8 tropical s… 0           35     1004
#> 10 Amy    1975     6    29     6  34   -74.8 tropical s… 0           40     1002
#> # … with more rows, and 2 more variables: ts_diameter <dbl>, hu_diameter <dbl>

Created on 2021-03-11 by the reprex package (v1.0.0)

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 a pull request may close this issue.

1 participant