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__       -65.9   -65.6   1.40   1.17   -68.7    -64.3     1.00    1893.
#>  2 alpha        0.380   0.380 0.218  0.216    0.0231   0.740   1.00    4801.
#>  3 beta[1]     -0.668  -0.659 0.248  0.247   -1.09    -0.273   1.00    4573.
#>  4 beta[2]     -0.271  -0.267 0.224  0.229   -0.634    0.0845  1.00    4645.
#>  5 beta[3]      0.678   0.666 0.266  0.259    0.248    1.12    1.00    4505.
#>  6 log_lik[1]  -0.515  -0.508 0.0990 0.0965  -0.689   -0.362   1.00    4844.
#>  7 log_lik[2]  -0.403  -0.384 0.147  0.139   -0.669   -0.199   1.00    4585.
#>  8 log_lik[3]  -0.495  -0.459 0.218  0.202   -0.898   -0.206   1.00    4890.
#>  9 log_lik[4]  -0.452  -0.433 0.153  0.150   -0.726   -0.239   1.00    4491.
#> 10 log_lik[5]  -1.18   -1.16  0.278  0.275   -1.67    -0.765   1.00    5130.
#> # ℹ 95 more rows
#> # ℹ 1 more variable: ess_tail <dbl>
# }