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.

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__       -66.0   -65.7   1.42  1.27  -68.7    -64.3     1.00    2381.
#>  2 alpha        0.379   0.377 0.223 0.224   0.0200   0.754   1.00    4356.
#>  3 beta[1]     -0.663  -0.664 0.252 0.252  -1.08    -0.250   1.00    4356.
#>  4 beta[2]     -0.270  -0.263 0.223 0.215  -0.645    0.0924  1.00    4293.
#>  5 beta[3]      0.686   0.676 0.269 0.263   0.261    1.15    1.00    4246.
#>  6 log_lik[1]  -0.516  -0.511 0.101 0.101  -0.692   -0.364   1.00    4361.
#>  7 log_lik[2]  -0.401  -0.381 0.149 0.144  -0.676   -0.193   1.00    4797.
#>  8 log_lik[3]  -0.494  -0.460 0.214 0.203  -0.897   -0.207   1.00    4344.
#>  9 log_lik[4]  -0.450  -0.431 0.154 0.150  -0.725   -0.233   1.00    4169.
#> 10 log_lik[5]  -1.19   -1.17  0.280 0.279  -1.67    -0.767   1.00    4463.
#> # ℹ 95 more rows
#> # ℹ 1 more variable: ess_tail <dbl>
# }