R/helper_formula.R

Defines functions get_vars rhs_vars lhs_vars

## Internal helper functions for formula parsing.
## These replace the orphaned formula.tools package with base R equivalents.

## Get variable names from the left-hand side of a formula.
## Returns character(0) for one-sided formulas (e.g., ~ A + B).
lhs_vars <- function(formula) {
    if (length(formula) == 2) {
        return(character(0))
    }
    all.vars(formula[[2]])
}

## Get variable names from the right-hand side of a formula.
rhs_vars <- function(formula) {
    if (length(formula) == 2) {
        all.vars(formula[[2]])
    } else {
        all.vars(formula[[3]])
    }
}

## Get all resolved variable names from a formula, expanding dot notation.
## Equivalent to formula.tools::get.vars(formula, data=data).
get_vars <- function(formula, data = NULL) {
    if (!is.null(data) && "." %in% all.vars(formula)) {
        attr(terms(formula, data = data), "term.labels")
    } else {
        all.vars(formula)
    }
}

Try the hettx package in your browser

Any scripts or data that you put into this service are public.

hettx documentation built on Feb. 24, 2026, 5:08 p.m.