I am trying to write my first function using rlang
and I am having some trouble fixing the following error.
I've read the vignette, but didn't see a good example of what I'm trying to do.
library(babynames)
library(tidyverse)
name_graph <- function(data, name, sex){
name <- enquo(name)
sex <- enquo(sex)
data %>%
filter_(name == !!name, sex == !!sex) %>%
select(year, prop) %>%
ggplot()+
geom_line(mapping = aes(year, prop))
}
name_graph(babynames, Robert, M)
I'm expecting my distribution graph, but getting an error:
Called from: abort(paste_line("Quosures can only be unquoted within a quasiquotation context.", "", " # Bad:", " list(!!myquosure)", "", " # Good:", " dplyr::mutate(data, !!myquosure)"))