Hello experts. I think this is a somewhat advanced topic. Let me start with an example code.
test_data = tibble(a = sample(c("group 1","group 2"), 100, replace=T),
b = rnorm(100))
test_fun = function(data, group, value) {
data %>% group_by(group) %>% summarize(mean=mean(value))
}
test_fun(test_data, a, b)
#Error: Must group by variables found in `.data`.
#* Column `group` is not found.
test_fun(test_data, quote(a), quote(b))
#Error: Must group by variables found in `.data`.
#* Column `group` is not found.
As shown in the example, I want to make a function that takes a tibble and unquoted variable names as arguments and do some data transformation with tidyverse workflow. I expected quote(variable) would work, but it didn't (I don't quite understand why). How can I make this function work?