Running rstan on grid engine causing compiling error

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

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, ...).