Skip to content

Should summarise.data.frame respect .groups="rowwise"? #5422

Description

@gergness

This is admittedly a small niche, but noticed the inconsistency when checking that my method matched for summarise matched dplyr's behavior.

In most situations this summarise would return a single row data.frame and so the groups wouldn't matter, but because we can now return multiple rows, it seems inconsistent to me.

library(dplyr)

df <- mtcars %>% 
  summarize(x = range(mpg), .groups = "rowwise")

df
#>      x
#> 1 10.4
#> 2 33.9

inherits(df, "rowwise_df") # expected TRUE
#> [1] FALSE
class(df)
#> [1] "data.frame"

df_grp <- mtcars %>% 
  group_by(cyl) %>% 
  summarize(x = range(mpg), .groups = "rowwise")

df_grp
#> # A tibble: 6 x 2
#> # Rowwise:  cyl
#>     cyl     x
#>   <dbl> <dbl>
#> 1     4  21.4
#> 2     4  33.9
#> 3     6  17.8
#> 4     6  21.4
#> 5     8  10.4
#> 6     8  19.2

inherits(df_grp, "rowwise_df")
#> [1] TRUE
class(df_grp)
#> [1] "rowwise_df" "tbl_df"     "tbl"        "data.frame"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions