Quosure objects wrap an expression with a lexical
enclosure. This is a powerful quoting (see `base::quote()`

and `quo()`

) mechanism that makes it possible to carry and
manipulate expressions while making sure that its symbolic content
(symbols and named calls, see `is_symbolic()`

) is correctly looked
up during evaluation.

`new_quosure()`

creates a quosure from a raw expression and an environment.`as_quosure()`

is useful for functions that expect quosures but allow specifying a raw expression as well. It has two possible effects: if`x`

is not a quosure, it wraps it into a quosure bundling`env`

as scope. If`x`

is an unscoped quosure (see`is_quosure()`

),`env`

is used as a default scope. On the other hand if`x`

has a valid enclosure, it is returned as is (even if`env`

is not the same as the formula environment).While

`as_quosure()`

always returns a quosure (a one-sided formula), even when its input is a formula or a definition,`as_quosureish()`

returns quosureish inputs as is.

as_quosure(x, env = caller_env()) as_quosureish(x, env = caller_env())

x | An object to convert. |
---|---|

env | An environment specifying the lexical enclosure of the quosure. |

# Sometimes you get unscoped formulas because of quotation: f <- ~~expr inner_f <- f_rhs(f) str(inner_f)#> language ~expr#> [1] FALSE#> <quosure: base> #> ~~expr# Or convert expressions or any R object to a validly scoped quosure: as_quosure(quote(expr), base_env())#> <quosure: base> #> ~expr#> <quosure: empty> #> ~10L# While as_quosure() always returns a quosure (one-sided formula), # as_quosureish() returns quosureish objects: as_quosure(a := b)#> <quosure: local> #> ~`:=`(a, b)as_quosureish(a := b)#> <quosure: local> #> ~`:=`(a, b)as_quosureish(10L)#> <quosure: local> #> ~10L