group_by NULL using across

Before, I used group_by_at to group by a vector of strings or by NULL:


grouping_1 <- c("cyl", "vs")
grouping_2 <- NULL

mtcars %>% group_by_at(grouping_1)
mtcars %>% group_by_at(grouping_2) # this leaves mtcars ungrouped

The help of group_by_at indicates that the function is superseded and that across should be used instead. But, grouping by NULL gives an error

mtcars %>% group_by(across(grouping_1))
mtcars %>% group_by(across(grouping_2)) #this gives an error

For me, group_by_at used in the way described has been useful because in my functions I can use the same code without checking every time whether the grouping argument is empty or not.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.