Let's say I wanted to create a function that internally uses some functions of the dplyr or any tidyverse that use this type of syntax.
By way of illustration:
exemplo <- function(df, predicado, sumario) {
df %>% filter(predicado) %>%
summarise(sumario)
}
Ideally, this function should run like this:
exemplo(mtcars, cyl == 4, mean(wt))
But when I squeeze it, I get it.
Error in filter_impl (.data, quo): object 'cyl' not found
The expected result is the same as when we do
mtcars %>% filter(cyl == 4) %>%
summarise(mean(wt))
# mean(wt)
# 1 2.285727
Then I ask you how to use the dplyr in the body of a function without giving up using the power and simplicity of its syntax?