Formula operations and coercion as a supplement to update.formula()

formula_add(frm1, frm2)

formula_poly(chr1, n, noint = FALSE, y = NULL)

formula_nth(frm1, n)

formula_to_interaction_matrix(frm1)

formula_chr_to_form(rhs, lhs = character(0))

to_str(chr1, collapse = "+")

terms_labels(frm1)

simplify_rhs(object)

# S3 method for formula
simplify_rhs(object)

# S3 method for character
simplify_rhs(object)

as_rhs_frm(object)

as_lhs_frm(object)

as_rhs_chr(object, string = FALSE)

as_lhs_chr(object, string = FALSE)

unique_formula(list_of_formulas)

Arguments

frm1, frm2

Formulas to be coerced to character vectors.

chr1

Character vector to be coerced to formulas.

n

Positive integer.

noint

Boolean.

y

Response

rhs, lhs

right-hand-side and left-hand-side for formula (as characters)

collapse

Character to use as separator.

object

Character vector or formula.

string

Boolean.

list_of_formulas

list of formulas

Examples


formula_poly("z", 2)
#> ~z + I(z^2)
#> <environment: 0x56d1062b0b90>
formula_poly("z", 2, noint=TRUE)
#> ~-1 + z + I(z^2)
#> <environment: 0x56d105813748>

as_rhs_chr(c("a", "b", "z"))
#> [1] "abz"
as_rhs_chr(c("a*b", "z"))
#> [1] "a*bz"

as_rhs_chr(y~a+b+z)
#> [1] "a+b+z"
as_rhs_chr(y~a+b+z, string=TRUE)
#> [1] "a+b+z"
as_rhs_chr(y~a+b+z)
#> [1] "a+b+z"
as_rhs_chr(y~a*b+z)
#> [1] "a+a:b+b+z"
as_rhs_chr(y~a*b+z, string=TRUE)
#> [1] "a+a:b+b+z"

as_lhs_chr(y~a*b+z)
#> [1] "y"
as_lhs_chr(log(y)~a*b+z)      ## Not what one might expect
#> [1] "log" "y"  
as_lhs_chr(cbind(y, u)~a*b+z) ## Not what one might expect
#> [1] "cbind" "y"     "u"    

formula_chr_to_form(c("a*b", "z"))
#> ~a * b + z
#> <environment: 0x56d10826b730>
formula_chr_to_form(c("a*b", "z"), "y")
#> y ~ a * b + z
#> <environment: 0x56d1051be950>
formula_chr_to_form(c("a*b", "z"), "log(y)")
#> log(y) ~ a * b + z
#> <environment: 0x56d1085fdb40>

formula_add(y~a*b+z, ~-1)
#> y ~ a + a:b + b + z
#> <environment: 0x56d0fdc54db0>
formula_add(y~a*b+z, ~a:b)
#> y ~ a + a:b + b + z
#> <environment: 0x56d1055d8430>