RStan problem installing

Hello. I’ve been trying unsuccessfully to install RStan. I’m using the latest version of R (version 4.0.3) and RStudio (version 1.3.1093) on a PC running Windows 10 and I followed all the instructions at

which sent me to

where I also followed the instructions. For example when I run Sys.getenv(“BINPREF”) I get ``` as desired, and the RTools4 installation also went fine with the check install.packages(“jsonlite”, type = “source”) going through ok.

I then installed RSTAN from source via

install.packages(“rstan”, type = “source”)

It seemed to go fine. BUt when I ran the demo code

library(rstan)
example(stan_model,run.dontrun = TRUE)

the rstan library wasn’t recognized. So this was unexpected and I just tried installing rstan directly via Tools -> Install packages from RStudio. This went fine and I’ve checked that rstan, StanHeaders and inline packages are at or above the required versions. But when I run the demo code again, i.e.

library(rstan)
example(stan_model,run.dontrun = TRUE)

I obtain the following error

“Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
cc1plus.exe: fatal error: \icnas2.cc.ic.ac.uk/mhaugh/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-40~1.3/etc/x64/Makeconf:229: file795037b99fe.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”

I actually have tried installing it a couple of times, but am at a loss. This is probably my third attempt over the past 3-4 years and each time I fail. I’ve never had any issues installing other software, Python packages etc. but RStan and I think MatlabStan has always defeated me. Any ideas?

Thanks

It looks like you are installing packages to a network mounted drive, which is not good for packages (such as Rcpp, RcppEigen, RcppParallel, BH, and StanHeaders) whose header files are needed during compilation. If it is possible to install packages to a physical disk, that is much easier to get working.

Thanks for getting back to me. That’s good to know re network mounted drives. However, I also tried installing it on my laptop (again running Windows 10 and the latest versions of R and RStudio) which does not have any nettwork mounted drives but the installation failed. I followed everything on

ending with

install.packages(“rstan”, type = “source”)

where I did see a few warnings / errors during the installation process. It ended with

"ERROR: dependencies ‘StanHeaders’, ‘RcppParallel’, ‘V8’ are not available for package ‘rstan’

  • removing ‘C:/Users/MB-Haugh/Documents/R/win-library/4.0/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status"

I don’t know what’s the best way to resolve this. There’s a ton of output from the attempt to install rstan but the last part of the message seems to suggest that it’s again a problem with StanHeaders and a couple of other packages.

That error message is not correct. Which CRAN mirror were you using?

Well I had just installed the latest version of R and RStudio and simply went with

install.packages(“rstan”, type = “source”)

so presumably the default mirror for my location. Any idea what the easiest way is to determine this?

Thanks…

getOption("repos")

Thanks. That produced:

                   CRAN 

https://cran.rstudio.com/
attr(,“RStudio”)
[1] TRUE

OK. I would just try

install.packages("rstan", dependencies = TRUE)

again since all the necessary packages are, in fact, findable from that RStudio mirror.

That worked. Thanks Ben.