# Problem Loading cmdstan VB Draws into R for Analysis

**URL:** <https://discourse.mc-stan.org/t/problem-loading-cmdstan-vb-draws-into-r-for-analysis/17984>\
**Category:** Developers\
**Created:** [September 11, 2020, 3:42pm UTC](https://discourse.mc-stan.org/t/problem-loading-cmdstan-vb-draws-into-r-for-analysis/17984 "2020-09-11T15:42:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![npretnar](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@npretnar](https://discourse.mc-stan.org/u/npretnar)\
**Post date:** [September 11, 2020, 3:42pm UTC](https://discourse.mc-stan.org/t/problem-loading-cmdstan-vb-draws-into-r-for-analysis/17984/1 "2020-09-11T15:42:29Z")

</div>

I’m using rstan 2.21.2 and cmdstan 2.24. I run a Variational Bayes estimator in cmdstan and then proceed to load the posterior draws into R using

```stan
# R code
x = read_stan_csv("posterior.csv") 
show(x)

```

At load I get the error:

_Warning message:_  
_In parse\_stancsv\_comments(comments) : line with “Elapsed Time” not found_

At show(x) I get the error:

_Error in dim(s1) \<- c(length(tidx), length(m) + 5L) : dims [product 2460] do not match the length of object [2214]_

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [September 11, 2020, 5:10pm UTC](https://discourse.mc-stan.org/t/problem-loading-cmdstan-vb-draws-into-r-for-analysis/17984/2 "2020-09-11T17:10:31Z")

</div>

I’m not sure if `read_stan_csv()` ever worked with the results from variational inference. @bgoodri do you know if this was supposed to work? If it is I can investigate and debug, if it’s not then we should add an informative error message about that instead of having it just fail with this weird error.

Either way, @npretnar we have a new package CmdStanR for running CmdStan from R and that works with variational inference and shouldn’t have any trouble reading the CmdStan results back into R:

> **[R Interface to CmdStan](https://mc-stan.org/cmdstanr/)**
>
> A lightweight interface to Stan .
> The CmdStanR interface is an alternative to RStan that calls the command 
> line interface for compilation and running algorithms instead of interfacing 
> with C++ via Rcpp. Methods are provided for...

So you can run CmdStan from your R session that way, but if you’d rather run CmdStan from the command line directly you can still use CmdStanR’s `read_cmdstan_csv()` function after:

> **[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().
