My question builds on a similar one by imposing an additional constraint that the name of each variable should appear only once.
Consider a data frame
Here's a hacky function that uses unexported functions from dplyr so it is not future proof, but you can specify a different summary for each column.
summarise_with <- function(.tbl, .funs) {
funs <- enquo(.funs)
syms <- syms(tbl_vars(.tbl))
calls <- dplyr:::as_fun_list(.funs, funs, caller_env())
stopifnot(length(syms)==length(calls))
cols <- purrr::map2(calls, syms, ~dplyr:::expr_substitute(.x, quote(.), .y))
cols <- purrr::set_names(cols, purrr::map_chr(syms, rlang::as_string))
summarize(.tbl, !!!cols)
}
Then you could do
df %>% summarise_with(list(mean, sum))
and not have to type the column names at all.