I am trying to write a wrapper function around ggplot, but I keep coming up with an error when unquoting a function parameter:
Error in !enquo(x) : invalid argument type
I have re-read the dplyr programming guide, and thought I understood it and have used tidyeval previously in implementing functions using dplyr verbs eg group_by and mutate. This brought me to the ggplot documentation for aes where I found this example:
scatter_by <- function(data, x, y) {
ggplot(data) + geom_point(aes(!!enquo(x), !!enquo(y)))
}
scatter_by(mtcars, disp, drat)
When I run this in RStudio 1.1.383, I get the error:
Error in !enquo(x) : invalid argument type
I am using ggplot2 version 2.2.1 and dplyr 0.7.4
I have tried using rlang::UQ(enquo(x)) instead of !! but I still get an error.