# Saving the dso from expose\_stan\_functions

**URL:** <https://discourse.mc-stan.org/t/saving-the-dso-from-expose-stan-functions/705>\
**Category:** RStan\
**Created:** [May 30, 2017, 1:14pm UTC](https://discourse.mc-stan.org/t/saving-the-dso-from-expose-stan-functions/705 "2017-05-30T13:14:32Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![wds15](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wds15/32/908_2.png) [@wds15](https://discourse.mc-stan.org/u/wds15)\
**Post date:** [September 18, 2017, 11:21am UTC](https://discourse.mc-stan.org/t/saving-the-dso-from-expose-stan-functions/705/4 "2017-09-18T11:21:58Z")

</div>

Thank you guys for pointing me in this direction. This `rcpp.cache.dir` is a life-saver. A few notes for anyone who finds this: If you want to avoid recompilation every time you load the exposed stan functions, you have to follow these steps:

1. set the `rcpp.cache.dir` option as described avove
2. Use the `stanc_builder` function with the (default) `obfuscate_model_name=FALSE` setting in order to ensure that the same c++ code is generated each time
3. pass the result from stanc\_builder into expose\_stan\_functions

So like this:

```R
options(rccp.cpp.dir="cache")
model_src <- stanc_builder("foo.stan")
expose_stan_functions(model_src)

```

Also make sure that a recent enough `Rcpp` is installed which supports dso caching.

@bgoodri: Should we make `expose_stan_functions` by default such that the model name is not obfuscated? This would lead to easier caching of this. Maybe we could even switch on the caching stuff if rstan\_auto\_write is set to true?

User who use exposed stan functions will love this caching.

---

_[View the full topic](https://discourse.mc-stan.org/t/saving-the-dso-from-expose-stan-functions/705)._
