Installing RStan on a Virtual Machine

Hi ,

I have been having issues installing RStan on a virtual machine.

Virtual machine:

  • Windows 10 enterprise
  • Version 1909
  • 64-bit, x64 processor


  • 4.1.0
  • 64-bit


  • 1.4.1106

Instructions followed are based on Stan Installation Help

Configuring C++ Toolchain

  1. Sys.getenv("BINPREF") returns ""
  2. Installed Rtools40 64-bit from R tools link and saved at C:\rtools40:
  3. Added Rtools to the path variable using writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
  4. Sys.which("make") returns: "C::\\rtools40\\usr\\bin\\make.exe"
  5. Confirmed I can install packages from source
  6. Completed the makevars configuration step

Installing RStan

  1. Installing RStan seems to work, but it returns a directory that has “local_” in front of my user account. This does not happen with my laptop
  2. library(rstan) returns

Example Model

Please note that I removed the code output from lines 2:368 for both sets of model outputs to ensure the character limit was not breached. If you would like to see the full output please let me know.

example(stan_model, package = "rstan", run.dontrun = TRUE) returns

stn_md> stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
stn_md> mod <- stan_model(model_code = stancode, verbose = TRUE)
TRANSLATING MODEL '73fc79f8b1915e8208c736914c86d1a1' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '73fc79f8b1915e8208c736914c86d1a1'.
Error in open.connection(con, open = mode) : 
  Could not resolve host:
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found
COMPILING THE C++ CODE FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW.
OS: x86_64, mingw32; rstan: 2.21.2; Rcpp: 1.0.6; inline: 0.3.19 
 >> setting environment variables: 
LOCAL_LIBS =  "C:/Program Files/R/R-4.1.0/library/rstan/lib/x64/libStanServices.a" -L"C:/Program Files/R/R-4.1.0/library/StanHeaders/libs/x64" -lStanHeaders -L"C:/Program Files/R/R-4.1.0/library/RcppParallel/lib/x64" -ltbb
PKG_CPPFLAGS =   -I"C:/Program Files/R/R-4.1.0/library/Rcpp/include/"  -I"C:/Program Files/R/R-4.1.0/library/RcppEigen/include/"  -I"C:/Program Files/R/R-4.1.0/library/RcppEigen/include/unsupported"  -I"C:/Program Files/R/R-4.1.0/library/BH/include" -I"C:/Program Files/R/R-4.1.0/library/StanHeaders/include/src/"  -I"C:/Program Files/R/R-4.1.0/library/StanHeaders/include/"  -I"C:/Program Files/R/R-4.1.0/library/RcppParallel/include/"  -I"C:/Program Files/R/R-4.1.0/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include "C:/Program Files/R/R-4.1.0/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp"  -std=c++1y
>> Program source :
   1 : 
369 : }
make cmd is
  make -f "C:/PROGRA~1/R/R-41~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-41~1.0/share/make/" -f "//WWG00M.ROOTDOM.NET/BFS-HOME/t8ciabn-R0328854/.R/" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file185c28a45681.dll" WIN=64 TCLBIN=64 OBJECTS="file185c28a45681.o"
make would use
make: *** No rule to make target 'file185c28a45681.o', needed by 'file185c28a45681.dll'.  Stop.
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
369: }
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  make: *** No rule to make target 'file185c28a45681.o', needed by 'file185c28a45681.dll'.  Stop.

Also, I noted that Sys.getenv("HOME") returns "\\\\WWG00M.ROOTDOM.NET\\BFS-HOME\\*username*-R0328854".

Any help you can provide would be greatly appreciated.


1 Like

sorry to hear you are having problems. I don’t see any immediate red flag, and not completely sure what is happening. Maybe @rok_cesnovar has seen some of this before?

In any case, you may try using latest (currently not on CRAN for stupid reasons) rstan via Repository for distributing (some) stan-dev R packages | r-packages or use cmdstanr which is often easier to get running.

Hope you can get this resolved quickly.