fit-method-save_object: Save fitted model object to a file

fit-method-save_objectR Documentation

Save fitted model object to a file

Description

This method is a wrapper around base::saveRDS() that ensures that all posterior draws and diagnostics are saved when saving a fitted model object. Because the contents of the CmdStan output CSV files are only read into R lazily (i.e., as needed), the ⁠$save_object()⁠ method is the safest way to guarantee that everything has been read in before saving.

Usage

save_object(file, ...)

Arguments

file

(string) Path where the file should be saved.

...

Other arguments to pass to base::saveRDS() besides object and file.

See Also

CmdStanMCMC, CmdStanMLE, CmdStanVB, CmdStanGQ

Examples

## Not run: 
fit <- cmdstanr_example("logistic")

temp_rds_file <- tempfile(fileext = ".RDS")
fit$save_object(file = temp_rds_file)
rm(fit)

fit <- readRDS(temp_rds_file)
fit$summary()

## End(Not run)


stan-dev/cmdstanr documentation built on March 21, 2024, 5:44 a.m.