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")
#> Model executable is up to date!
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 x 10 #> variable mean median sd mad q5 q95 rhat ess_bulk #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 lp__ -66.0 -65.7 1.45 1.26 -68.8 -64.3 1.00 2256. #> 2 alpha 0.377 0.377 0.220 0.215 0.0127 0.746 1.00 4115. #> 3 beta[1] -0.666 -0.663 0.247 0.250 -1.07 -0.267 1.00 4477. #> 4 beta[2] -0.276 -0.278 0.228 0.233 -0.658 0.0915 1.00 4296. #> 5 beta[3] 0.681 0.672 0.277 0.269 0.247 1.15 1.00 4142. #> 6 log_lik… -0.517 -0.512 0.0995 0.101 -0.694 -0.368 1.00 4197. #> 7 log_lik… -0.403 -0.381 0.151 0.141 -0.684 -0.194 1.00 4422. #> 8 log_lik… -0.500 -0.465 0.215 0.207 -0.904 -0.210 1.00 4562. #> 9 log_lik… -0.449 -0.429 0.156 0.154 -0.730 -0.228 1.00 4022. #> 10 log_lik… -1.18 -1.16 0.282 0.281 -1.67 -0.754 1.00 4546. #> # … with 95 more rows, and 1 more variable: ess_tail <dbl>
# }