Skip to content

Can't ungroup using group_by() #615

Closed
@davidchall

Description

@davidchall

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions