Skip to content

Add number of groups to grouped_epi_archive$print #278

Open
@brookslogan

Description

@brookslogan

Printing a grouped tibble provides the grouping variables and number of groups. We should try to mirror that with grouped_epi_archives. Note that it gets messy with the use of .drop=FALSE (especially with a mix of factor and non-factor grouping variables, which seems inadvisable).

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
tibble(g=c(1,1,1,2,3), a=c(1,2,2,2,2)) %>% group_by(g,a)
#> # A tibble: 5 × 2
#> # Groups:   g, a [4]
#>       g     a
#>   <dbl> <dbl>
#> 1     1     1
#> 2     1     2
#> 3     1     2
#> 4     2     2
#> 5     3     2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=c(1,2,2,2,2)) %>% group_by(g)
#> # A tibble: 5 × 2
#> # Groups:   g [3]
#>   g         a
#>   <fct> <dbl>
#> 1 a         1
#> 2 a         2
#> 3 a         2
#> 4 b         2
#> 5 c         2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=c(1,2,2,2,2)) %>% group_by(g, .drop=FALSE)
#> # A tibble: 5 × 2
#> # Groups:   g [5]
#>   g         a
#>   <fct> <dbl>
#> 1 a         1
#> 2 a         2
#> 3 a         2
#> 4 b         2
#> 5 c         2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=c(1,2,2,2,2)) %>% group_by(g,a, .drop=FALSE)
#> # A tibble: 5 × 2
#> # Groups:   g, a [6]
#>   g         a
#>   <fct> <dbl>
#> 1 a         1
#> 2 a         2
#> 3 a         2
#> 4 b         2
#> 5 c         2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=factor(c(1,2,2,2,2))) %>% group_by(g,a, .drop=FALSE)
#> # A tibble: 5 × 2
#> # Groups:   g, a [10]
#>   g     a    
#>   <fct> <fct>
#> 1 a     1    
#> 2 a     2    
#> 3 a     2    
#> 4 b     2    
#> 5 c     2

Created on 2023-03-15 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3very low priorityREPLImproved print, errors, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions