@@ -561,6 +561,9 @@ CmdStanFit$set("public", name = "unconstrain_variables", value = unconstrain_var
561
561
# '
562
562
unconstrain_draws <- function (files = NULL , draws = NULL ,
563
563
format = getOption(" cmdstanr_draws_format" , " draws_array" )) {
564
+ if (! (format %in% valid_draws_formats())) {
565
+ stop(" Invalid draws format requested!" , call. = FALSE )
566
+ }
564
567
if (! is.null(files ) || ! is.null(draws )) {
565
568
if (! is.null(files ) && ! is.null(draws )) {
566
569
stop(" Either a list of CSV files or a draws object can be passed, not both" ,
@@ -582,6 +585,8 @@ unconstrain_draws <- function(files = NULL, draws = NULL,
582
585
}
583
586
draws <- maybe_convert_draws_format(private $ draws_ , " draws_matrix" )
584
587
}
588
+
589
+ chains <- posterior :: nchains(draws )
585
590
586
591
model_par_names <- self $ metadata()$ stan_variables [self $ metadata()$ stan_variables != " lp__" ]
587
592
model_variables <- self $ runset $ args $ model_variables
@@ -598,7 +603,9 @@ unconstrain_draws <- function(files = NULL, draws = NULL,
598
603
unconstrained <- private $ model_methods_env_ $ unconstrain_draws(private $ model_methods_env_ $ model_ptr_ , draws )
599
604
uncon_names <- private $ model_methods_env_ $ unconstrained_param_names(private $ model_methods_env_ $ model_ptr_ , FALSE , FALSE )
600
605
names(unconstrained ) <- repair_variable_names(uncon_names )
601
- maybe_convert_draws_format(unconstrained , format , .nchains = posterior :: nchains(draws ))
606
+ unconstrained $ .nchains <- chains
607
+
608
+ do.call(function (... ) { create_draws_format(format , ... ) }, unconstrained )
602
609
}
603
610
CmdStanFit $ set(" public" , name = " unconstrain_draws" , value = unconstrain_draws )
604
611
0 commit comments