Let's say I want to add 1 to every value of a column using dplyr
and standard evaluation.
I can do :
library(dplyr)
data <- head(iris)
var <- "Sepal.Length"
mutate(data, !!rlang::sym(var) := !!quo(`+`(!!rlang::sym(var), 1)))
But what if I would like to use +
as binary operator and not as function ?
I can't figure out how to write the +
with a symbol in a quosure.
In most of my attempts I got an error for trying to use a non-numeric argument (the symbol for example) with the binary operator +
.
With the deprecated mutate_
you can use lazyeval::interp
which allowed you to do it easily :
mutate_(data, .dots = setNames(list(lazyeval::interp(~var + 1, var = as.symbol(var))), var))
Any help would be appreciated. Thanks.