# Error running R code on Linux computing cluster

**URL:** https://discourse.mc-stan.org/t/error-running-r-code-on-linux-computing-cluster/4690
**Category:** Interfaces
**Created:** [June 29, 2018, 5:22pm UTC](https://discourse.mc-stan.org/t/error-running-r-code-on-linux-computing-cluster/4690 "2018-06-29T17:22:14Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![Rehab](https://avatars.discourse-cdn.com/v4/letter/r/9fc348/32.png) [@Rehab](https://discourse.mc-stan.org/u/Rehab)
#### Post date: [April 27, 2019, 6:11pm UTC](https://discourse.mc-stan.org/t/error-running-r-code-on-linux-computing-cluster/4690/11 "2019-04-27T18:11:56Z")

</div>

Hi Johanna,

Here is the link for the solution:

> [@Using Rstan on a cluster](https://discourse.mc-stan.org/t/using-rstan-on-a-cluster/5092):
>
> Hello Everyone, Operating System: CentOS 7 RStan Version: 2.17.3 Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars"))) CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function CXXFLAGS += -Wno-ignored-attributes -Wno-deprecated-declarations Output of devtools::session\_info("rstan"): \> devtools::session\_info(“rstan”) Session info ------------------------------------------------------------------ setting value v…

First, I compiled the stan code without the data, directly on the management node and saved the compiled file with extension .RData. This takes few seconds.  
Then, in the R file, I added a statement to call the compiled file. After that, you can submit the R file to the SLURM.

Here is my previous answer after the discussion with members of stan forums:

“ But I found a solution to get around the compilation error. First, I compiled the stan model, without data, on the “Management Server” and saved the compiled model with the extension .RData as follow:

sm ← stan\_model(file = ‘a.stan’, save\_dso = TRUE)  
save(‘sm’, file = ‘sm.RData’)

Then, I submitted my R file to the SLURM and it works :)

The R file includes the following:

load(“sm.RData”)

… simulated data…

fit ← sampling(sm, data=list(K, N, J, y, dir\_alpha ), pars=c(“pi”, “mu”, “theta”, “beta”, “alpha”, “prob”), warmup = 2000, iter = 5000, chains = 3)

Thanks a lot for everyone helped to solve this problem. Thanks for the Stan forums.”

---

_[View the full topic](https://discourse.mc-stan.org/t/error-running-r-code-on-linux-computing-cluster/4690)._
