dvnames: Title models with their dependent variables

View source: R/dvnames.R

dvnamesR Documentation

Title models with their dependent variables

Description

A convenience function for use with a regression model or list of regression models. Returns a named list of models, where the names are the models' respective dependent variables. If the dependent variables are labelled, the labels are used as names. Pass your list of models to dvnames before sending to modelsummary to automatically get dependent variable-titled columns.

Usage

dvnames(models, number = FALSE, strip = FALSE, fill = "Model")

Arguments

models

A regression model or list of regression models

number

Should the models be numbered (1), (2), etc., in addition to their dependent variable names?

strip

Boolean toggle for how dependent variable names are extracted. When strip is TRUE, the function calls insight::find_response(), typically returning the raw variable name stripped of any transformation notation (e.g., log(y)). When strip is FALSE, it first tries to parse the formula stored in the model object and return the characters before the first ~, keeping any transformation text; it falls back to insight::find_response() if the formula cannot be parsed. In both cases, if insight::find_response() and labels fail, the name is replaced by fill.

fill

If insight::find_response() cannot find a response, the column title to use in its place. Set to ' ' to leave blank.

Examples


m1 <- lm(mpg ~ hp, data = mtcars)
m2 <- lm(mpg ~ hp + wt, data = mtcars)

# Without dvnames, column names are (1) and (2)
modelsummary(list(m1, m2))

# With dvnames, they are "mpg" and "mpg"
modelsummary(dvnames(list(m1,m2)))


modelsummary documentation built on Feb. 13, 2026, 5:10 p.m.