tidypredict_save: Save and re-load a parsed model

View source: R/save.R

tidypredict_saveR Documentation

Save and re-load a parsed model

Description

tidypredict_save() writes a parsed model to a YAML file, and tidypredict_load() reads one back. Together they persist a model's prediction formula without needing the original model object, or the package that fitted it, to be available later.

Use these rather than calling yaml::write_yaml() directly. yaml defaults to 7 significant digits, which is not enough to represent a split threshold exactly: a re-loaded tree model can then send rows down a different branch than the model it was saved from.

Usage

tidypredict_save(x, file)

tidypredict_load(file)

Arguments

x

A fitted model, or a parsed model from parse_model(). Fitted models are parsed before being saved.

file

Path to write the YAML file to, or read it from.

Value

tidypredict_save() returns x, invisibly, so it can be used in a pipe. tidypredict_load() returns a parsed model object.

Examples

model <- lm(mpg ~ wt + cyl, data = mtcars)

path <- tempfile(fileext = ".yml")
tidypredict_save(model, path)

loaded <- tidypredict_load(path)
tidypredict_fit(loaded)


tidypredict documentation built on Oct. 18, 2026, 5:06 p.m.