simplify_formula: Simplify formula with inline functions

View source: R/simplify_formula.R

simplify_formulaR Documentation

Simplify formula with inline functions

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}

Extracts all variables from a formula object and creates a new formula with all predictor variables added together without the inline functions.

E.g.:

y ~ x*z + log(a) + (1|b)

becomes

y ~ x + z + a + b.

This is useful when passing a formula to recipes::recipe() for preprocessing a dataset, as used in the preprocess_functions().

Usage

simplify_formula(formula, data = NULL, string_out = FALSE)

Arguments

formula

Formula object.

If a string is passed, it will be converted with as.formula().

When a side only contains a NULL, it is kept. Otherwise NULLs are removed.

An intercept (1) will only be kept if there are no variables on that side of the formula.

data

data.frame. Used to extract variables when the formula contains a ".".

string_out

Whether to return as a string. (Logical)

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Examples

# Attach cvms
library(cvms)

# Create formula
f1 <- "y ~ x*z + log(a) + (1|b)"

# Simplify formula (as string)
simplify_formula(f1)

# Simplify formula (as formula)
simplify_formula(as.formula(f1))

cvms documentation built on Sept. 11, 2024, 6:22 p.m.