@@ -561,6 +561,9 @@ CmdStanFit$set("public", name = "unconstrain_variables", value = unconstrain_var
561561# '
562562unconstrain_draws <- function (files = NULL , draws = NULL ,
563563 format = getOption(" cmdstanr_draws_format" , " draws_array" )) {
564+ if (! (format %in% valid_draws_formats())) {
565+ stop(" Invalid draws format requested!" , call. = FALSE )
566+ }
564567 if (! is.null(files ) || ! is.null(draws )) {
565568 if (! is.null(files ) && ! is.null(draws )) {
566569 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,
582585 }
583586 draws <- maybe_convert_draws_format(private $ draws_ , " draws_matrix" )
584587 }
588+
589+ chains <- posterior :: nchains(draws )
585590
586591 model_par_names <- self $ metadata()$ stan_variables [self $ metadata()$ stan_variables != " lp__" ]
587592 model_variables <- self $ runset $ args $ model_variables
@@ -598,7 +603,9 @@ unconstrain_draws <- function(files = NULL, draws = NULL,
598603 unconstrained <- private $ model_methods_env_ $ unconstrain_draws(private $ model_methods_env_ $ model_ptr_ , draws )
599604 uncon_names <- private $ model_methods_env_ $ unconstrained_param_names(private $ model_methods_env_ $ model_ptr_ , FALSE , FALSE )
600605 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 )
602609}
603610CmdStanFit $ set(" public" , name = " unconstrain_draws" , value = unconstrain_draws )
604611
0 commit comments