Problem getting brms and Stan working on Windows 10 networked computers

Next week, I am scheduled to run a couple of workshops at my uni on Bayesian modelling using brms and Stan. Many of the participants have Windows 10 laptops with a network drive. We have tried and failed to get brms/Stan to work on two such computers. However, it works with no issue on Macs and on Windows 10 that do not have network drive.

Does anyone have any suggestions as to how to solve this problem?

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file1c486da3db.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
 #include <stan/model/model_header.hpp>
                                       ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: file1c486da3db.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
 Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file1c486da3db.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
 #include <stan/model/model_header.hpp>
                                       ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: file1c486da3db.o] Error 1 
 Error in sink(type = "output") : invalid connection

You may have to install the necessary R packages into a directory on the network drive. The error message is telling you that it cannot find StanHeaders in the place(s) that it looked. So, you need to figure out where StanHeaders is installed and where it is looking. The StanHeaders package can be found with

system.file(package = "StanHeaders")

whereas to find where the compiler is looking you may need to do something like

Sys.setenv(PKG_CPPFLAGS = "-v")

or add the -v to CXX11FLAGS in ~/.R/Makevars.

Thank you for helping.

Running system.file(package = "StanHeaders") in the RStudio console, returns an empty result of "".

Running Sys.setenv(PKG_CPPFLAGS = "-v") doesn’t seem to solve the problem – I get the same error.

Any suggestions?

OK. It can’t find StanHeaders. Where does the package get put when you do install.packages("StanHeaders")

The -v option can’t fix any problem, but it can tell you what directories the compiler searched for before encountering that error.

I won’t have access to that computer till tomorrow (Sydney time). But I am pretty sure that both R and StanHeaders are installed on the laptop’s internal drive (not the network). If StanHeaders needs to be on the network drive, is there a way to install it there or, better, is there a way to get R to “look” in the right place?

Regarding Sys.setenv(PKG_CPPFLAGS = "-v"), running that produces no printed output.

Possibly you can get it to look on the internal drive by calling the .libPaths() function appropriately. Also, you may have to call stan or stan_model with verbose = TRUE to see the full output when something goes wrong.

Thanks – I will try that out tomorrow!

We think we have a solution (a set of steps). There may well be some redundancies in here, but I post the instructions I will sending out to attendees of my workshop in case it is useful for anyone else. I can confirm these steps have worked on one networked Windows 10 computer but we have not yet managed to test it on another.

If you have a Windows laptop with a network drive (i.e., most Windows computers provided by the university), you will need to take some special steps to get R, RStudio, brms and associated packages all working together. These steps are necessary to ensure that everything is installed on your computer’s internal drive rather than on the network, and that R.

Uninstall your current (and possibly out-of-date) versions of R and RStudio.

Download the latest version of R from https://cran.r-project.org/bin/windows/base/. Install it by right-clicking on the file and choosing “run as administrator” (this will install it on your internal drive).

Download the latest version of RStudio from https://rstudio.com/products/rstudio/download/#download. Install it by right-clicking on the file and choosing “run as administrator” (this will install it on your internal drive).

Download RTools35 from https://cran.r-project.org/bin/windows/Rtools/. Install it by right-clicking on the file and choosing “run as administrator” (this will install it on your internal drive).

Create a folder called “R" on the C drive, and within that a subfolder called “library”.

Open Control Panel (not Settings), then System and Security > System > Advanced system settings > Environment variables. Click New… and enter R_LIBS_USER as the Variable name, and C:/R/library as the Variable value.

Open RStudio and run .libPaths(). If it returns C:/R/library as the first, or only, listed path, everything is good. If it does not, run .libPaths("C:/R/library”).

Close RStudio and re-open. Install the following packages by running:

install.packages(“brms”)
install.packages(“tidyverse”)
install.packages(“car”)
install.packages(“bayesplot”)
install.packages(“rstan”)
install.packages(“lme4”)

Then load those packages with:

library(brms)
library(tidyverse)
library(car)
library(bayesplot)
library(rstan)
library(lme4)

To check that brms and Stan are working correctly, run the following in RStudio’s console:

bprior1 <- prior(student_t(5,0,10), class = b) +
  prior(cauchy(0,2), class = sd)
fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
            data = epilepsy, family = poisson(), prior = bprior1)
fit1

Hello all,
I reopen this post as I am experiencing a similar problem, obtaining exactly the same error when running the 8schools example in a networked computer.

I followed Andy’s step and now have a library in :C/R_library, where also R (3.6.1), RStudio (1.2.1335) and RTools 3.5, are installed (C:/Program Files/).

However I am still having problems, this time obtaining the following error:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from C:/R_library/StanHeaders/include/stan/math/rev/core/build_vari_array.hpp:4:0,
from C:/R_library/StanHeaders/include/stan/math/rev/core.hpp:5,
from C:/R_library/StanHeaders/include/stan/math/rev/mat.hpp:4,
from C:/R_library/StanHeaders/include/stan/math.hpp:4,
from C:/R_library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from filec40572777ea.cpp:8:
C:/R_library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:23: fatal error: Eigen/Dense: No such file or directory
#include <Eigen/Dense>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: filec40572777ea.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-36~1.1/bin/x64/R CMD SHLIB filec40572777ea.cpp 2> filec40572777ea.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Anyone experienced this issue before?

I could provide the verbose = TRUE output as well if needed.

Huge thanks to @andymilne for the steps to resolve this problem that had been plaguing me. Followed the steps and the models are now chugging away on Easter morning!
Communities sharing this type of help are priceless and deeply appreciated by all.

1 Like