names -> data-mask, via across(all_of())

Setup:

  • outer function, my_group_by(), expects character names
  • inner function, dplyr::group_by(), expects data-masking

Building the bridge:

  • all_of() takes character names and is a tidy selector
  • across() performs selection and returns a tibble
my_group_by <- function(data, vars) {
  data %>% dplyr::group_by(
    across(        # <- takes selection; returns tibble
      all_of(vars) # <- takes character vector; performs tidy-selection
    )
  )
}

mtcars %>% my_group_by(c("cyl", "am"))