# Rstan::read\_stan\_csv throwing error with cmdstan models (versions 2.35)

**URL:** <https://discourse.mc-stan.org/t/rstan-read-stan-csv-throwing-error-with-cmdstan-models-versions-2-35/35665>\
**Category:** General\
**Tags:** rstan, cmdstanr\
**Created:** [June 27, 2024, 7:13pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-throwing-error-with-cmdstan-models-versions-2-35/35665 "2024-06-27T19:13:18Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [July 30, 2024, 7:12am UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-throwing-error-with-cmdstan-models-versions-2-35/35665/7 "2024-07-30T07:12:31Z")

</div>

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:

```r
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)
}

```

---

_[View the full topic](https://discourse.mc-stan.org/t/rstan-read-stan-csv-throwing-error-with-cmdstan-models-versions-2-35/35665)._
