RStan error when running example(stan_model, package = "rstan", run.dontrun = TRUE)

I have successfully installed RStan on Windows 10 by following the steps here: RStan Getting Started · stan-dev/rstan Wiki · GitHub

But when I run the example:
example(stan_model, package = “rstan”, run.dontrun = TRUE)

I receive an error message. I have uninstalled RStan and installed it again, but I receive the same error. I must mention that because I do not have full admin rights on the computer, so the RStan package is installed in \userfs/myuser/w2k/R.

(The most recent versions of) R, RStudio and rtools are installed in C:\Program Files.

In case it helps, I managed to run many Stan programs (the examples and my own) from Command Prompt with no problems.

The error message is as follows:

ERROR(s) during compilation: source code errors or compiler configuration errors!

(Here I deleted some lines because of lack of space)

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
cc1plus.exe: fatal error: \userfs/myuser/w2k/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directorycompilation terminated.make: *** [C:/PROGRA~1/R/R-4.0.5/etc/x64/Makeconf:229: fileb9c6d6418e.o] Error 1
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found

Thank you!

This error is occurring because your R packages are installed on a network drive (\userfs/myuser/w2k) rather than on your local computer. This causes problems for R when it looks for files during RStan model compilation. You’ll need to move your package directory to a local folder on your computer.

If you’re not sure how to do that, I’ve previously written up some instructions in this post. That post assumed that the new package directory should be in C:\Users\R, so just update that if you want it somewhere else

Thank you! It worked following your instructions.