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

1 Like

Thank you! It worked following your instructions.

Hi @andrjohns , what about this one, could you please help me?
I got this error below when running the example. Basically, I’m struggling to install stan into my RStudio.

Error in compileCode(f, code, language = language, verbose = verbose) :
C:/rtools40/ucrt64/bin/…/lib/gcc/x86_64-w64-mingw32/10.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file15dc35a86da6.o:file15dc35a86da6.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file15dc35a86da6.o:file15dc35a86da6.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/ucrt64/bin/…/lib/gcc/x86_64-w64-mingw32/10.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file15dc35a86da6.o:file15dc35a86da6.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observe

See the Getting Started Guide

Yes, I have installed the RTool, but still does not work. Any advice?

The section I linked to was about installing the version of rstan from the Stan repo, did you complete that step?

yes, I did. Still gave the same error (as in the previous message).

What output do you get from:

if (!requireNamespace("devtools")) {
  install.packages("devtools")
}
devtools::session_info("rstan")