20.6 Other facts about quosures
Formulas were the inspiration for closures because they also capture an expression and an environment
f <- ~runif(3)
str(f)
#> Class 'formula' language ~runif(3)
#> ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
There was an early version of tidy evaluation with formulas, but there’s no easy way to implement quasiquotation with them.
They are actually call objects
with an attribute to store the environment
Nested quosures
With quosiquotation we can embed quosures in expressions.
q2 <- new_quosure(expr(x), env(x = 1))
q3 <- new_quosure(expr(x), env(x = 100))
nq <- expr(!!q2 + !!q3)
And evaluate them
But for printing it’s better to use expr_print(x)