`is_formula()`

tests if `x`

is a call to `~`

. `is_bare_formula()`

tests in addition that `x`

does not inherit from anything else than
`"formula"`

. `is_formulaish()`

returns `TRUE`

for both formulas and
definitions of the type `a := b`

.

is_formula(x, scoped = NULL, lhs = NULL)
is_bare_formula(x, scoped = NULL, lhs = NULL)
is_formulaish(x, scoped = NULL, lhs = NULL)

## Arguments

x |
An object to test. |

scoped |
A boolean indicating whether the quosure or formula
is scoped, that is, has a valid environment attribute. If `NULL` ,
the scope is not inspected. |

lhs |
A boolean indicating whether the formula
or definition has a left-hand side. If `NULL` ,
the LHS is not inspected. |

## Details

The `scoped`

argument patterns-match on whether the scoped bundled
with the quosure is valid or not. Invalid scopes may happen in
nested quotations like `~~expr`

, where the outer quosure is validly
scoped but not the inner one. This is because `~`

saves the
environment when it is evaluated, and quoted formulas are by
definition not evaluated.

## See also

`is_quosure()`

and `is_quosureish()`

## Examples

x <- disp ~ am
is_formula(x)

#> [1] TRUE

is_formula(~10)

#> [1] TRUE

is_formula(10)

#> [1] FALSE

#> [1] TRUE

#> [1] FALSE

# Note that unevaluated formulas are treated as bare formulas even
# though they don't inherit from "formula":
f <- quote(~foo)
is_bare_formula(f)

#> [1] FALSE

# However you can specify `scoped` if you need the predicate to
# return FALSE for these unevaluated formulas:
is_bare_formula(f, scoped = TRUE)

#> [1] FALSE

is_bare_formula(eval(f), scoped = TRUE)

#> [1] TRUE

# There is also a variant that returns TRUE for definitions in
# addition to formulas:
is_formulaish(a ~ b)

#> [1] TRUE

is_formulaish(a := b)

#> [1] TRUE