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())#> <quosure> #> expr: ^expr #> env: 0x7f828b01dd08#> <quosure> #> expr: ^10L #> env: empty# Sometimes you get unscoped formulas because of quotation: f <- ~~expr inner_f <- f_rhs(f) str(inner_f)#> language ~expr#> [1] FALSE# With as_quosure() you ensure that this kind of unscoped formulas # will be granted a default environment: as_quosure(inner_f, base_env())#> <quosure> #> expr: ^~expr #> env: 0x7f828b01dd08