Tidyeval with quoted function



Hi, I'm new to tidyeval and wanted to do the following:

# This is working as expected
eval_tidy(quo("a" %>% paste("b")))
# "a b"

I expected the following snipped to return the same result as above but gettingsomething else. What am I missing here? How could I get the above result when having var_1 and var_2 as quo's?

var_1 <- quo("a")
var_2 <- quo(paste("b"))
eval_tidy(quo(!!var_1 %>% !!var_2))
# . ~ paste("b")
# <environment: 0x0000000015d8a798>

edit: It seems as if replacing "quo" with "expr" does the trick. Why is this not working with quo?


Your var_2 is a quosure of the expression paste("b"), so I'm a little unclear on what your expected output is.


var_1 <- quo("a")
#> <quosure>
#>   expr: ^"a"
#>   env:  empty
var_2 <- quo(paste("b"))
#> <quosure>
#>   expr: ^paste("b")
#>   env:  global
eval_tidy(quo(!!var_1 %>% !!var_2))
#> . ~ paste("b")
#> <environment: 0x7f99840aee70>
eval_tidy(expr(!!var_1 %>% !!var_2))
#> . ~ paste("b")
#> <environment: 0x7fd33db6caf8>

Created on 2018-08-08 by the reprex package (v0.2.0.9000).


When you replace quo by expr for the two vars, it is working as expected
I still try to understand the difference between both to be able to explain it clearly by words. I think I understand it conceptually but not enough to explain clearly. Great example then ! :wink:

library(magrittr, warn.conflicts = FALSE) # for %>%
var_1 <- expr("a")
var_2 <- expr(paste("b"))
eval_tidy(quo(!!var_1 %>% !!var_2))
#> [1] "a b"

Created on 2018-08-08 by the reprex package (v0.2.0).