Here's a small example of how to accomplish that. You pass in a string of args, we use syms from rlang to turn that into a list of symbols. We then use the !!! unquote-splice operator to group by those symbols.
library(rlang)
library(dplyr)
fun <- function(df, args){
by <- syms(args)
df %>%
group_by(!!!by) %>%
summarize_all(mean)
}
Using this example with mtcars:
> fun(mtcars, c("cyl"))
# A tibble: 3 x 11
cyl mpg disp hp drat wt qsec vs am gear carb
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 4.00 26.7 105 82.6 4.07 2.29 19.1 0.909 0.727 4.09 1.55
2 6.00 19.7 183 122 3.59 3.12 18.0 0.571 0.429 3.86 3.43
3 8.00 15.1 353 209 3.23 4.00 16.8 0 0.143 3.29 3.50