Before, I used
group_by_at to group by a vector of strings or by NULL:
library(tidyverse) 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
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.