Passing a list of arguments to a function with quasiquotation
问题 I am trying to write a function in R that summarizes a data frame according to grouping variables. The grouping variables are given as a list and passed to group_by_at , and I would like to parametrize them. What I am doing now is this: library(tidyverse) d = tribble( ~foo, ~bar, ~baz, 1, 2, 3, 1, 3, 5 4, 5, 6, 4, 5, 1 ) sum_fun <- function(df, group_vars, sum_var) { sum_var = enquo(sum_var) return( df %>% group_by_at(.vars = group_vars) %>% summarize(sum(!! sum_var)) ) } d %>% sum_fun(group