# Reading into R from cmdstan

**URL:** <https://discourse.mc-stan.org/t/reading-into-r-from-cmdstan/40868>\
**Category:** Interfaces\
**Created:** [January 25, 2026, 7:20pm UTC](https://discourse.mc-stan.org/t/reading-into-r-from-cmdstan/40868 "2026-01-25T19:20:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drezap](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/drezap/32/11168_2.png) [@drezap](https://discourse.mc-stan.org/u/drezap)\
**Post date:** [January 25, 2026, 7:20pm UTC](https://discourse.mc-stan.org/t/reading-into-r-from-cmdstan/40868/1 "2026-01-25T19:20:22Z")

</div>

What’s the go to method for reading in a `cmdstan` output into R?

I’m using `read_stan_csv()`, which worked in a previous set up but not working now.

I see some talk about it but I’m not using cmdstanr.

I’m getting errors like:

`object 'n_kept' not found In addition: Warning message: In parse_stancsv_comments(comments) : NAs introduced by coercion`

But there’s no MCMC diagnostic issues.

---

<div class="post-metadata">

**Author:** ![drezap](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/drezap/32/11168_2.png) [@drezap](https://discourse.mc-stan.org/u/drezap)\
**Post date:** [January 25, 2026, 7:51pm UTC](https://discourse.mc-stan.org/t/reading-into-r-from-cmdstan/40868/2 "2026-01-25T19:51:44Z")

</div>

> **[Read CmdStan CSV files into R — read\_cmdstan\_csv](https://mc-stan.org/cmdstanr/reference/read_cmdstan_csv.html)**
>
> read\_cmdstan\_csv() is used internally by CmdStanR to read
> CmdStan's output CSV files into R. It can also be used by CmdStan users as
> a more flexible and efficient alternative to rstan::read\_stan\_csv(). See
> the Value section for details on the...

here

---

<div class="post-metadata">

**Author:** ![drezap](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/drezap/32/11168_2.png) [@drezap](https://discourse.mc-stan.org/u/drezap)\
**Post date:** [January 26, 2026, 2:33am UTC](https://discourse.mc-stan.org/t/reading-into-r-from-cmdstan/40868/3 "2026-01-26T02:33:08Z")

</div>

Yeah, I have some items from generated quantities I just want to get the vectors I’ve computed.

Before I could just use `samples = rstan::extract(csv)` and then `samples$y_pred_in` for in sample predictions, for example, trying to figure out how to do this in current rstan stack.

I just need the items I’ve generated in generated quantities, to see prediction accuracy, etc.

---

<div class="post-metadata">

**Author:** ![drezap](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/drezap/32/11168_2.png) [@drezap](https://discourse.mc-stan.org/u/drezap)\
**Post date:** [January 26, 2026, 3:13am UTC](https://discourse.mc-stan.org/t/reading-into-r-from-cmdstan/40868/4 "2026-01-26T03:13:12Z")

</div>

ok, for example

`fit = as_cmdstan_fit("foo.csv"); fit$draws("y_pred");`

closing this
