# Rstan::read\_stan\_csv chokes on NaN

**URL:** <https://discourse.mc-stan.org/t/rstan-read-stan-csv-chokes-on-nan/1646>\
**Category:** RStan\
**Created:** [August 22, 2017, 3:06pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-chokes-on-nan/1646 "2017-08-22T15:06:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sakrejda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/sakrejda/32/845_2.png) [@sakrejda](https://discourse.mc-stan.org/u/sakrejda)\
**Post date:** [August 22, 2017, 3:06pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-chokes-on-nan/1646/1 "2017-08-22T15:06:19Z")

</div>

For some reason rstan will not let me load output files with NaN values (which happen because the model  
program covers a variety of model types and outputs some irrelevant values). Is there a flag to create the  
object anyway?

```
> tp <- rstan::read_stan_csv(csvfiles=dir(pattern='output-chain-.\\.csv'))
Error in validObject(.Object) : 
  invalid class “stanfit” object: The following variables have undefined values: predicted_district_delta.1,The following variables have undefined values: predicted_district_delta.2,The following variables have undefined values: predicted_district_delta.3,The following variables have undefined values: predicted_district_delta.4,The following variables have undefined values: predicted_district_delta.5,The following variables have undefined values: predicted_district_delta.6,The following variables have undefined values: predicted_district_delta.7,The following variables have undefined values: predicted_district_delta.8,The following variables have undefined values: predicted_district_delta.9,The following variables have undefined values: predicted_district_delta.10,The following variables have undefined values: predicted_district_delta.11,The following variables have undefined values: predicted_district_delta.12,The following variables have undefined values: pre
In addition: Warning message:
closing unused connection 3 (output-chain-1.csv)

```

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [August 22, 2017, 3:18pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-chokes-on-nan/1646/2 "2017-08-22T15:18:23Z")

</div>

No. IIRC, having `NaN` values in the `stanfit` object causes problems. If something in generated quantities is irrelevant according to some static condition, then you should be able to make it be of length zero.

---

<div class="post-metadata">

**Author:** ![sakrejda](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/sakrejda/32/845_2.png) [@sakrejda](https://discourse.mc-stan.org/u/sakrejda)\
**Post date:** [August 22, 2017, 5:54pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-chokes-on-nan/1646/3 "2017-08-22T17:54:14Z")

</div>

sed is my new best friend, again.

---

<div class="post-metadata">

**Author:** ![anon79882417](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon79882417](https://discourse.mc-stan.org/u/anon79882417)\
**Post date:** [July 25, 2018, 2:11pm UTC](https://discourse.mc-stan.org/t/rstan-read-stan-csv-chokes-on-nan/1646/4 "2018-07-25T14:11:26Z")

</div>

I’m having the same issue. Can you please describe what you did?
