# Running rstan on grid engine causing compiling error

**URL:** https://discourse.mc-stan.org/t/running-rstan-on-grid-engine-causing-compiling-error/1508
**Category:** RStan
**Created:** [August 7, 2017, 5:03pm UTC](https://discourse.mc-stan.org/t/running-rstan-on-grid-engine-causing-compiling-error/1508 "2017-08-07T17:03:15Z")
**Posts on this page:** 2
**Page:** 2

<div class="post-metadata">

### Author: ![jnguyen](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@jnguyen](https://discourse.mc-stan.org/u/jnguyen)
#### Post date: [August 7, 2017, 10:34pm UTC](https://discourse.mc-stan.org/t/running-rstan-on-grid-engine-causing-compiling-error/1508/21 "2017-08-07T22:34:07Z")

</div>

Thanks for your reply.

I checked and saw that I did include that in my .R file where I called the function stan(). To be honest, I didn’t look into the issue as I was pressed for time and was looking for only a solution to carry out my evaluations…

Cheers

---

<div class="post-metadata">

### Author: ![jjramsey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jjramsey/32/3319_2.png) [@jjramsey](https://discourse.mc-stan.org/u/jjramsey)
#### Post date: [August 8, 2017, 2:59pm UTC](https://discourse.mc-stan.org/t/running-rstan-on-grid-engine-causing-compiling-error/1508/22 "2017-08-08T14:59:37Z")

</div>

For what it’s worth, I have an R program that I’ve used to compile the Stan file into an RDS file in advance, rather than resorting to `auto_write=TRUE`:

```
#!/usr/bin/env Rscript

library(tools)
library(optparse)
library(rstan)

option_list = list(
  make_option(c('--outputRDS', '-o'),
              help = 'Alternate name of output file'),
  make_option(c('--verbose', '-v'),
              help = 'Print intermediate compilation output',
              action = 'store_true',
              default = FALSE)
)

opts_args = parse_args(OptionParser(option_list=option_list,
                                    usage = "%prog [options] Stan-model-file"),
                       positional_arguments=1)

opts = opts_args$options
stanFile = opts_args$args

outputFile = NULL
if (is.null(opts$outputRDS)) {
   outputFile = sprintf("%s.rds", file_path_sans_ext(basename(stanFile)))
} else {
  outputFile = opts$outputRDS
}

myModel = stan_model(stanFile, verbose=opts$verbose, auto_write = FALSE, save_dso=TRUE)
saveRDS(myModel, file=outputFile)

```

Note that you’d need to install `optparse` from CRAN to use this script.

Anyway, this way you can avoid bothering with compilation on the compute nodes. Of course, you’d also need to modify the R code that you run on the compute nodes to use the RDS file, e.g. replacing `stan(file="your_stan_file.stan", ...)` with `myModel = readRDS("your_rds_file.rds")` followed by `sampling(myModel, ...)`.

[Previous page](https://discourse.mc-stan.org/t/running-rstan-on-grid-engine-causing-compiling-error/1508.md?page=1)
