Skip to content

Safely fit a linear model

Source: R/utils.R ยท Help: ?safe_lm

Wraps stats::lm() in a tryCatch block that logs the error via ht_log() and optionally attempts recovery (e.g., dropping rows with missing values) before rethrowing. This helper is used internally by diagnostic tests so failures are easier to debug.

Usage

safe_lm(formula, data, ..., .recover = TRUE)

Arguments

formula
Model formula.
data
Data frame to evaluate the formula in.
...
Additional arguments passed to stats::lm().
.recover
Logical flag controlling whether the helper should attempt automatic recovery strategies (e.g., removing problematic rows) before rethrowing the error.

Value

A fitted model object.