-
Notifications
You must be signed in to change notification settings - Fork 35
[BUG] Group by + summarise on 0-row tibble produces invalid output. #766
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Group by + summarise on 0-row tibble causes the summarised variable to be invalid.
Steps/Code to Reproduce
library(tidyverse)
library(collapse)
#> Warning: package 'collapse' was built under R version 4.4.2
#> collapse 2.0.17, see ?`collapse-package` or ?`collapse-documentation`
#>
#> Attaching package: 'collapse'
#> The following object is masked from 'package:lubridate':
#>
#> is.Date
#> The following object is masked from 'package:tidyr':
#>
#> replace_na
#> The following object is masked from 'package:stats':
#>
#> D
no_rows_tibble <- tibble::tibble(var_1 = character(), var_2 = numeric())
tmp <- no_rows_tibble |>
collapse::fgroup_by(var_1) |>
collapse::fsummarise(var_2 = sum(var_2))
length(tmp)
#> [1] 2
class(tmp[[2]])
#> [1] "NULL"
tmp2 <- no_rows_tibble |>
dplyr::group_by(var_1) |>
dplyr::summarise(var_2 = sum(var_2))
length(tmp2)
#> [1] 2
class(tmp2[[2]])
#> [1] "numeric"Created on 2025-04-23 with reprex v2.1.1
Expected behavior
class of the summarised variable should remain numeric
Additional context
Also reported here as it creates a vctrs internal error.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working