Usage
Formula(object)
## S3 method for class 'Formula'
formula(x, lhs = NULL, rhs = NULL,
collapse = FALSE, update = FALSE, drop = TRUE, ...)
as.Formula(x, ...)
is.Formula(object)
Details
Formula objects extend the basic formula objects. These extensions include multi-part formulas such as y ~ x1 + x2 | u1 + u2 + u3 | v1 + v2, multiple response formulas y1 + y2 ~ x1 + x2 + x3, multi-part responses such as y1 | y2 + y3 ~ x, and combinations of these.
The Formula creates a Formula object from a formula which can have the | operator on the left- and/or right-hand side (LHS and/or RHS). Essentially, it stores the original formula along with attribute lists containing the decomposed parts for the LHS and RHS, respectively.
The main motivation for providing the Formula class is to be able to conveniently compute model frames and model matrices or extract selected responses based on an extended formula language. This functionality is provided by methods to the generics model.frame, and model.matrix. For details and examples, see their manual page: model.frame.Formula.
In addition to these workhorses, a few further methods and functions are provided. By default, the formula() method switches back to the original formula. Additionally, it allows selection of subsets of the LHS and/or RHS (via lhs, and rhs) and collapsing multiple parts on the LHS and/or RHS into a single part (via collapse).
is.Formula checks whether the argument inherits from the Formula class.
as.Formula is a generic for coercing to Formula, the default method first coerces to formula and then calls Formula. The default and formula method also take an optional env argument, specifying the environment of the resulting Formula. In the latter case, this defaults to the environment of the formula supplied.
Methods to further standard generics print, update, and length are provided for Formula objects. The latter reports the number of parts on the LHS and RHS, respectively.