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.

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

Examples

# \dontrun{ 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()
#> # A tibble: 105 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 lp__ -65.9 -65.6 1.43 1.20 -68.8 -64.3 1.00 2291. #> 2 alpha 0.379 0.380 0.216 0.220 0.0214 0.735 1.00 4664. #> 3 beta[1] -0.668 -0.663 0.252 0.250 -1.09 -0.259 1.00 4187. #> 4 beta[2] -0.273 -0.265 0.225 0.224 -0.646 0.0856 1.00 3736. #> 5 beta[3] 0.682 0.679 0.261 0.258 0.260 1.10 1.00 3626. #> 6 log_lik[1] -0.515 -0.509 0.0979 0.0970 -0.683 -0.366 1.00 4695. #> 7 log_lik[2] -0.401 -0.380 0.144 0.136 -0.666 -0.200 1.00 4367. #> 8 log_lik[3] -0.496 -0.462 0.218 0.200 -0.899 -0.206 1.00 4031. #> 9 log_lik[4] -0.449 -0.432 0.150 0.144 -0.722 -0.237 1.00 3885. #> 10 log_lik[5] -1.18 -1.17 0.276 0.276 -1.68 -0.769 1.00 4020. #> # … with 95 more rows, and 1 more variable: ess_tail <dbl>
# }