Search code examples
ropencpustanrstan

openCPU and rstan - cannot open the connection


I'm using openCPU to create an API to estimate pretty basic models in rstan.

I have verified that my function works in my environment when called from a normal R console session, as opposed to called from openCPU.

But when called via openCPU, the response is the following:

cannot open the connection

In call:
file(con, "r")

By inserting checkpoints in the source of rstan, I've traced this to one call in R/cxxfunplus.R (link to line on github here):

dso <- new('cxxdso', sig = sig, dso_saved = save_dso, 
             dso_filename = dso_filename, 
             modulename = module_name, 
             system = R.version$system, 
             cxxflags = get_makefile_flags("CXXFLAGS"), 
             .CXXDSOMISC = new.env(parent = emptyenv()))

What in this call is trying to read a connection that might fail?


Solution

  • Figured this out - one of the two makefiles that rstan::get_makefile_txt is looking for doesn't exist when run under openCPU. The file is /usr/share/R/share/make.

    Fortunately the first makefile does exist and is sufficient, so this can be corrected by skipping the second makefile and only reading the first.

    Before the last line of rstan::get_makefile_text, I inserted the following:

    makefiles <- makefiles[file.exists(makefiles)]