The new curly curly method of tidy evaluation is explained in this article. Several examples are given demonstrating the use of this style of non-standard evaluation (NSE).
library(tidyverse)
# Example 1 --------------------------
max_by <- function(data, var, by) {
data %>%
group_by({{ by }}) %>%
summarise(maximum = max({{ var }}, na.rm = TRUE))
}
starwars %>% max_by(height)
starwars %>% max_by(height, by = gender)
# Example 2 --------------------------
summarise_by <- function(data, ..., by) {
data %>%
group_by({{ by }}) %>%
summarise(...)
}
starwars %>%
summarise_by(average = mean(height, na.rm = TRUE),
maximum = max(height, na.rm = TRUE),
by = gender)
I created some of my own functions and this is indeed a lot easier framework to develop in, instead of worrying about all the quosures and bangs and all of that.
However, this same article explains that we're not completely out of the woods yet:
You only need quote-and-unquote (with the plural variants enquos() and !!!) when you need to modify the inputs or their names in some way.
... and no example is provided. Not complaining, just asking if somebody can fill in the gap and provide an example. Not being fluent in Tidy evaluation, I really don't understand what the author is getting at with that quote (pardon the pun).
summarise(colNm :=
, you may need the !! – Tonlenquos()
or!!!
. Preferably I'd like to see an example of each one used individually. I wish it was in the referenced article but it's not. – Proteinaseand no example is provided. Not complaining, j
– Tonl