I think you don't need purrr and also you don't need tidyeval with {{ }} operator for what you want to do.
Your input df_var contains the argument for the function in characters. That mean you can use them as is with the *_at variant. By modifying mean_group you would get what you want.
You'll also need a group_by_all() to have a result by line of you tibble to reproduce the example you provide with t1 and t2.
here is what I got - with also a variant with purrr
suppressMessages(library(dplyr))
df_var <- tibble(group_var = c("Species", "Species"),
var = c("Sepal.Length", "Sepal.Width"))
# Argument will be character string not quosure.
# using the *_at variant
mean_group <- function(data, group_var, mean_var) {
data %>%
group_by_at(group_var) %>%
summarise_at(mean_var, list(mean = ~ mean(.x)))
}
# Using dplyr, naive approach
df_var %>%
group_by_all() %>%
mutate(tab = list(mean_group(iris, group_var, var))) %>%
tidyr::unnest_longer(tab)
#> # A tibble: 6 x 3
#> # Groups: group_var, var [2]
#> group_var var tab$Species $mean
#> <chr> <chr> <fct> <dbl>
#> 1 Species Sepal.Length setosa 5.01
#> 2 Species Sepal.Length versicolor 5.94
#> 3 Species Sepal.Length virginica 6.59
#> 4 Species Sepal.Width setosa 3.43
#> 5 Species Sepal.Width versicolor 2.77
#> 6 Species Sepal.Width virginica 2.97
# using purrr to get the same
df_var %>%
mutate(tab = purrr::pmap(., ~ mean_group(iris, .x, .y))) %>%
tidyr::unnest_longer(tab)
#> # A tibble: 6 x 3
#> group_var var tab$Species $mean
#> <chr> <chr> <fct> <dbl>
#> 1 Species Sepal.Length setosa 5.01
#> 2 Species Sepal.Length versicolor 5.94
#> 3 Species Sepal.Length virginica 6.59
#> 4 Species Sepal.Width setosa 3.43
#> 5 Species Sepal.Width versicolor 2.77
#> 6 Species Sepal.Width virginica 2.97
Created on 2020-02-05 by the reprex package (v0.3.0.9001)
Hi, cderv. In the situation I'm trying to solve, I can't modify the function mean_group to make it character aware. As in this example, the function I'm using receive quosures.