# Creating a cmdstanr object from cmdstan CSVs

**URL:** <https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349>\
**Category:** General\
**Tags:** cmdstanr\
**Created:** [January 21, 2021, 3:37pm UTC](https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349 "2021-01-21T15:37:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saudiwin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/saudiwin/32/1137_2.png) [@saudiwin](https://discourse.mc-stan.org/u/saudiwin)\
**Post date:** [January 21, 2021, 3:37pm UTC](https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349/1 "2021-01-21T15:37:19Z")

</div>

I am wondering if it is possible to construct a cmdstanr R6 object from cmdstan CSV files. The use case here is running a model on a cluster in MPI that I would subsequently like to make a cmdstanr model object from. I know it’s possible to create an rstan object from CSVs, but my current code is running off of cmdstanr. Cmdstanr does have a function for reading in CSVs, but no way to convert that to an actual object.

Is this a non-trivial problem or is there a helper function somewhere that could get me started?

Thanks for any help @jonah @rok_cesnovar

---

<div class="post-metadata">

**Author:** ![ahartikainen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ahartikainen/32/321_2.png) [@ahartikainen](https://discourse.mc-stan.org/u/ahartikainen)\
**Post date:** [January 21, 2021, 3:42pm UTC](https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349/2 "2021-01-21T15:42:32Z")

</div>

Here is one example for CmdStanPy, not sure if it helps.

(filepaths is a list of paths for csv files)

> <https://github.com/arviz-devs/arviz/blob/b96399653fc7be26dbdc91e363aa57bdd93055ed/arviz/tests/external_tests/test_data_cmdstanpy.py#L131>

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [January 21, 2021, 3:44pm UTC](https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349/3 "2021-01-21T15:44:08Z")

</div>

@saudiwin hey,

yes you can using `as_cmdstan_fit()`, but this is only available with the Github version of cmdstanr.

---

<div class="post-metadata">

**Author:** ![saudiwin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/saudiwin/32/1137_2.png) [@saudiwin](https://discourse.mc-stan.org/u/saudiwin)\
**Post date:** [January 21, 2021, 3:44pm UTC](https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349/4 "2021-01-21T15:44:12Z")

</div>

I’m running purely in R right now, but thanks!

---

<div class="post-metadata">

**Author:** ![saudiwin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/saudiwin/32/1137_2.png) [@saudiwin](https://discourse.mc-stan.org/u/saudiwin)\
**Post date:** [January 21, 2021, 3:57pm UTC](https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349/5 "2021-01-21T15:57:09Z")

</div>

Man you guys are really on the ball! I thought this would require a lot more plumbing. Will look into it, but that sounds like just what I need.

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [January 21, 2021, 3:58pm UTC](https://discourse.mc-stan.org/t/creating-a-cmdstanr-object-from-cmdstan-csvs/20349/6 "2021-01-21T15:58:46Z")

</div>

:)

Hopefully it does, if not, please do open an issue.

It returns a CmdstanFit-like object that support all the cmdstanfit stuff apart from a few functions that cant be supported just from the CSV files, like `$data_file()` etc.
