formula_term_labels: Retrieve term labels from a formula
Description
This function extracts the term labels from the right-hand side of a given R formula.
If an intercept is to be included (and a name for the intercept is provided), it will be added
as the first element of the returned vector.
A character vector containing the term labels. If an intercept is present and intercept is not NULL,
the intercept is returned first, followed by the remaining terms.
Arguments
formula
An R formula, e.g. ~ x1 * x2.
intercept
A character string indicating the name for the intercept. The default value is "(Intercept)".
If NULL is provided, the intercept will not be included, even if present in the formula.
Details
The default intercept value, "(Intercept)", is chosen to be consistent with the intercept label
returned by functions such as stats::lm(), stats::model.matrix(), and similar modeling functions.