These functions give information about the "current" group.

Can be used inside summarize(), mutate(), & filter()

cur_group_id.()

Examples

df <- data.table(
  x = 1:5,
  y = c("a", "a", "a", "b", "b")
)

df %>%
  mutate(
    across(c(x, y), ~ paste(cur_column(), .x))
  )
#> # A tidytable: 5 × 2
#>   x     y    
#>   <chr> <chr>
#> 1 x 1   y a  
#> 2 x 2   y a  
#> 3 x 3   y a  
#> 4 x 4   y b  
#> 5 x 5   y b  

df %>%
  summarize(data = list(cur_data()),
            .by = y)
#> # A tidytable: 2 × 2
#>   y     data               
#>   <chr> <list>             
#> 1 a     <tidytable [3 × 1]>
#> 2 b     <tidytable [2 × 1]>

df %>%
  mutate(group_id = cur_group_id(),
         .by = y)
#> # A tidytable: 5 × 3
#>       x y     group_id
#>   <int> <chr>    <int>
#> 1     1 a            1
#> 2     2 a            1
#> 3     3 a            1
#> 4     4 b            2
#> 5     5 b            2

df %>%
  mutate(group_rows = cur_group_rows(),
         .by = y)
#> # A tidytable: 5 × 3
#>       x y     group_rows
#>   <int> <chr>      <int>
#> 1     1 a              1
#> 2     2 a              2
#> 3     3 a              3
#> 4     4 b              1
#> 5     5 b              2