Parse model formula, create new variables by evaluating expressions and return parsed names and new data frame. These elements are ment to be used by other functions.

parse_formula(formula, data = NULL, keep_all_vars = FALSE)

Arguments

formula

A stats::formula() of form:

  • ~ y;

  • ~ y1 + y2;

  • y ~ x;

  • y1 + y2 ~ x1 + x2;

  • ~ y|condition;

  • y ~ x|condition;

  • y1 + y2 ~ x1 + x2|cond1 + cond2;

  • or similar.

Variables can be expressed as function, e.g., log(x), as.factor(x), which will be evaluated. Dot (.) is not accepted.

data

A data frame.

keep_all_vars

(logical) Flag indicating if all variables (even those not in formula) should be included in the output data. Expression keep_all_vars = TRUE has effect only if data is a data frame (and not NULL or an environment).

Value

A list with fields:

  1. formula - the formula used;

  2. names - alist of character vectors with names in formula arranged in certain way (see below);

  3. data - a data frame with variables and evaluated expressions in the formula and, optionally, with the remaining variables from the original data frame.

Contents of the field names:

  • all_names - all names (and expressions) in the formula;

  • y, x - names for "x" and "y" variables (except condition variables);

  • lhs, rhs - names in left-hand and right-hand side of formula (except condition variables);

  • condition - names of condition variables and expressions;

  • gr - if condition exists, gr is the same as condition, otherwise it is the same as x.