Tidy eval now supports glue strings
So this works great:
my_summarise5 <- function(data, mean_var ) {
data %>%
mutate(
"mean_{{mean_var}}" := mean({{ mean_var }}),
)
}
mtcars %>% my_summarise5(cyl)
But then
my_summarise5 <- function(data, mean_var ) {
data %>%
mutate(
"mean_{{mean_var}}" := mean({{ mean_var }}),
"mean_{{mean_var}}_plusone" := "mean_{{mean_var}}"+1
)
}
mtcars %>% my_summarise5(cyl)
Throws
Error: Problem with `mutate()` input `mean_cyl_plusone`.
x non-numeric argument to binary
Would some 'paste' or 'glue' thing in the "mean_{{mean_var}}_plusone" := "mean_{{mean_var}}"+1
part fix this?
Note this is obviously not a useful case, its a MWE for the syntax. I actually want to define two new columns with different names, one which uses the other ... otherwise I have to repeat and it also gets messy.