@@ -99,6 +99,35 @@ CmdStanFit <- R6::R6Class(
9999 )
100100)
101101
102+ # ' Materialize model object
103+ # '
104+ # ' @name fit-method-materialize
105+ # ' @aliases materialize
106+ # ' @description This method collects all posterior draws and diagnostics of a fitted
107+ # ' model object into R, since the contents of the CmdStan output CSV files are only
108+ # ' read into R lazily (i.e., as needed).
109+ # '
110+ # '
111+ # ' @seealso [`save_object`]
112+ # '
113+ # ' @examples
114+ # ' \dontrun{
115+ # ' fit <- cmdstanr_example("logistic")
116+ # ' object.size(fit)
117+ # '
118+ # ' fit$materialize()
119+ # ' object.size(fit)
120+ # ' }
121+ # '
122+ materialize <- function () {
123+ self $ draws()
124+ try(self $ sampler_diagnostics(), silent = TRUE )
125+ try(self $ init(), silent = TRUE )
126+ try(self $ profiles(), silent = TRUE )
127+ invisible (self )
128+ }
129+ CmdStanFit $ set(" public" , name = " materialize" , value = materialize )
130+
102131# ' Save fitted model object to a file
103132# '
104133# ' @name fit-method-save_object
@@ -123,7 +152,7 @@ CmdStanFit <- R6::R6Class(
123152# ' @param ... Other arguments to pass to [base::saveRDS()] (for `format = "rds"`)
124153# ' or `qs2::qs_save()` (for `format = "qs2"`).
125154# '
126- # ' @seealso [`CmdStanMCMC`], [`CmdStanMLE`], [`CmdStanVB`], [`CmdStanGQ`]
155+ # ' @seealso [`CmdStanMCMC`], [`CmdStanMLE`], [`CmdStanVB`], [`CmdStanGQ`], [`materialize`]
127156# '
128157# ' @examples
129158# ' \dontrun{
@@ -138,10 +167,7 @@ CmdStanFit <- R6::R6Class(
138167# ' }
139168# '
140169save_object <- function (file , format = c(" rds" , " qs2" ), ... ) {
141- self $ draws()
142- try(self $ sampler_diagnostics(), silent = TRUE )
143- try(self $ init(), silent = TRUE )
144- try(self $ profiles(), silent = TRUE )
170+ self $ materialize()
145171 format <- match.arg(format )
146172 if (format == " rds" ) {
147173 saveRDS(self , file = file , ... )
0 commit comments