as_quosure {rlang} | R Documentation |
While new_quosure()
wraps any R object (including expressions,
formulas, or other quosures) into a quosure, as_quosure()
converts formulas and quosures and does not double-wrap.
as_quosure(x, env = caller_env()) new_quosure(expr, env = caller_env())
x |
An object to convert. Either an expression or a formula. |
env |
The original context of the context expression. |
expr |
The expression wrapped by the quosure. |
Like the rest of the rlang package, new_quosure()
and
as_quosure()
are maturing.
as_quosureish()
is deprecated as of rlang 0.2.0. This function
assumes that quosures are formulas which is currently true but
might not be in the future.
# as_quosure() converts expressions or any R object to a validly # scoped quosure: as_quosure(quote(expr), base_env()) as_quosure(10L, base_env()) # Sometimes you get unscoped formulas because of quotation: f <- ~~expr inner_f <- f_rhs(f) str(inner_f) # In that case testing for a scoped formula returns FALSE: is_formula(inner_f, scoped = TRUE) # With as_quosure() you ensure that this kind of unscoped formulas # will be granted a default environment: as_quosure(inner_f, base_env())