I have a similar error and behavior, and if I add the verbose flag to the compilation:
library(rstan)
stan_code <- structure("data {\n int<lower=0> J; // number of schools\n real y[J]; // estimated treatment effect (school j)\n real<lower=0> sigma[J]; // std err of effect estimate (school j)\n}\nparameters {\n real mu;\n real theta[J];\n real<lower=0> tau;\n}\nmodel {\n theta ~ normal(mu, tau); \n y ~ normal(theta,sigma);\n}",
model_name2 = "eight_schools")
sm <- rstan::stan_model(model_code = stan_code,verbose=TRUE)
I get the error:
g++.exe: error: Johnson/Documents/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
I believe you’ll get the different behaviour when not loading RStan first if you have spaces in the path to your home directory.
This is because the compilation arguments to include Eigen.hpp
header slightly differ depending on whether RStan is loaded first.
If I load RStan, the compilation argument includes:
-include C:/Users/Andrew Johnson/Documents/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp
Because there’s no quotations around the call, it interprets it as two separate commands (split at the space between ‘Andrew’ and ‘Johnson’).
If I don’t load RStan first, the compilation argument includes:
-include stan/math/prim/mat/fun/Eigen.hpp
Where the relative addressing bypasses the issues with the space