If the end goal is a named list where each element is an array of posterior samples for a given variable, you could implement the extract_samples
function for cmdstanr
and posterior
as:
extract_samples <- function(fit_obj) {
vars <- fit_obj$metadata()$stan_variables
draws <- posterior::as_draws_rvars(fit_obj$draws())
lapply(vars, \(var_name){
posterior::draws_of(draws[[var_name]], with_chains = FALSE)
}) |> setNames(vars)
}