Skip to contents

create a formula of the form leftterm ~ rightterms[1] + rightterms[2] + ...

Usage

toFormula(leftterm, rightterms, as.formula = TRUE)

Arguments

leftterm

character. Left term of the formula

rightterms

vector of character. Right terms of the formula to be concatenated with "+".

as.formula

if TRUE (default) the formula object is returned, otherwise the formula string (character)

Value

formula object as generated by formula or formula string (character) of the form leftterm ~ rightterms[1] + rightterms[2] + ... if as.formula is FALSE

Examples

f1 <- toFormula("y", c("x1", "x2"))
f2 <- toFormula("y", paste0("x", 1:20))
  
f3 <- toFormula("BMI", c("height", "mass"), as.formula = FALSE)
  
# f1 and f2 are formulas ...
class(f1)
#> [1] "formula"
class(f2)
#> [1] "formula"
  
# ... but f3 is just "character"
class(f3)
#> [1] "character"