# \`rstan::read\_stan\_csv\` Fails to Read CSV Output from cmdstan When \`thin=\` is Specified

**URL:** <https://discourse.mc-stan.org/t/rstan-read-stan-csv-fails-to-read-csv-output-from-cmdstan-when-thin-is-specified/14168>\
**Category:** Developers\
**Created:** [April 7, 2020, 10:08pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-fails-to-read-csv-output-from-cmdstan-when-thin-is-specified/14168 "2020-04-07T22:08:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff-predictwise](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@jeff-predictwise](https://discourse.mc-stan.org/u/jeff-predictwise)\
**Post date:** [April 7, 2020, 10:08pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-fails-to-read-csv-output-from-cmdstan-when-thin-is-specified/14168/1 "2020-04-07T22:08:28Z")

</div>

When I run cmdstan with the `thin=` parameter set, I get a warning when I read the resulting CSV with `stan::read_stan_csv`, and I suspect the data is corrupted (seeing a lot of zero fill in the matricies).

```
In rstan::read_stan_csv(c("/data/jeff/run20200407/chain1.csv", "/data/jeff/run20200407/chain2.csv", :
  the number of iterations after warmup found (250) does not match iter/warmup/thin from CSV comments (50,50,50,50)

```

I see someone did submit a PR to fix the issue ([https://github.com/stan-dev/rstan/pull/692](https://github.com/stan-dev/rstan/pull/692)) in the past but unclear to me if it ever made it into a release. It seems pretty straightforward to fix. If someone can confirm this a real problem I will submit a PR as soon as I can.

In case it helps, my CSV header looks like this:

```
# stan_version_major = 2
# stan_version_minor = 22
# stan_version_patch = 1
# model = my_model
# method = sample (Default)
# sample
# num_samples = 250
# num_warmup = 3750
# save_warmup = 0 (Default)
# thin = 5
# adapt
# engaged = 1 (Default)
# gamma = 0.050000000000000003 (Default)
# delta = 0.90000000000000002
# kappa = 0.75 (Default)
# t0 = 10 (Default)
# init_buffer = 40
# term_buffer = 50 (Default)
# window = 25 (Default)
# algorithm = hmc (Default)
# hmc
# engine = nuts (Default)
# nuts
# max_depth = 10 (Default)
# metric = diag_e (Default)
# metric_file = (Default)
# stepsize = 1 (Default)
# stepsize_jitter = 0 (Default)
# id = 2
# data
# file = /data/data.R
# init = 2 (Default)
# random
# seed = 12345
# output
# file = /data/chain2.csv
# diagnostic_file = (Default)
# refresh = 20

```

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [April 7, 2020, 10:44pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-fails-to-read-csv-output-from-cmdstan-when-thin-is-specified/14168/2 "2020-04-07T22:44:35Z")

</div>

> [@jeff-predictwise](#):
>
> but unclear to me if it ever made it into a release. I

The Merged tag under the name indicates it was merged into the code base. That should mean it’s in any release that’s been done since the merge.

I can believe thinning for reads is a problem. Our I/O around the output is a mess we’ve been trying to fix for half a dozen years now, but there are so many conflicting opinions on how to proceed that we can’t seem to make any progress.

---

<div class="post-metadata">

**Author:** ![jeff-predictwise](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@jeff-predictwise](https://discourse.mc-stan.org/u/jeff-predictwise)\
**Post date:** [April 7, 2020, 11:37pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-fails-to-read-csv-output-from-cmdstan-when-thin-is-specified/14168/3 "2020-04-07T23:37:22Z")

</div>

Ok copy that :)

I believe I can run the model equivalently without thinning, so I’ll probably proceed that way, thanks.
