Is it possible to use the rlang tidy evaluation operator {{
within an lm formula?
I know that you can use the double curly braces to define a general function such as this:
my_scatter <- function(df, xvar, yvar) {
ggplot(df) +
geom_point(aes(x = {{xvar}}, y = {{yvar}}))
}
my_scatter(mpg, cty, hwy)
But I was wondering whether there was a way to make a similar call within formulas such as inside lm():
my_lm <- function(df, yvar, xvar) {
lm({{yvar}} ~ {{xvar}} , data = df)
}
my_lm(mpg, cty, hwy)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…