Similar to this: pass function arguments to both dplyr and ggplot
I have in the past used !!sym() without any rememberable headache.
However, now I get an error when I try this:
library(rlang)
library(tidyverse)
diamond_plot <- function (data, group, metric) {
quo_group <- sym(group)
quo_metric <- sym(metric)
data %>%
group_by(!! quo_group) %>%
summarise(price = mean(!! quo_metric)) %>%
ggplot(aes(x = !! quo_group, y = !! quo_metric)) +
geom_col()
}
diamond_plot(diamonds, "clarity", "price")
The error is
Error in !quo_group : invalid argument type
Did I miss something?