f_rhs
extracts the right-hand side, f_lhs
extracts the left-hand
side, and f_env
extracts the environment in which the formula was defined.
All functions throw an error if f
is not a formula.
Value
f_rhs
and f_lhs
return language objects (i.e. atomic
vectors of length 1, a name, or a call). f_env
returns an
environment.
Examples
f_rhs(~ 1 + 2 + 3)
#> 1 + 2 + 3
f_rhs(~ x)
#> x
f_rhs(~ "A")
#> [1] "A"
f_rhs(1 ~ 2)
#> [1] 2
f_lhs(~ y)
#> NULL
f_lhs(x ~ y)
#> x
f_env(~ x)
#> <environment: 0x557a345fdf38>
f <- as.formula("y ~ x", env = new.env())
f_env(f)
#> <environment: 0x557a3440a880>