Rstan install trouble

330 : {
331 : }
332 :
333 : //stan::math::ChainableStack ad_stack;
334 : rstan::io::rlist_ref_var_context rcontext_;
335 : unsigned int random_seed_;
336 : };
337 :
338 : Rcpp::XPtrstan::model::model_base model_ptr(stan_model_holder* smh) {
339 : Rcpp::XPtrstan::model::model_base model_instance(new stan_model(smh->rcontext_, smh->random_seed_), true);
340 : return model_instance;
341 : }
342 :
343 : Rcpp::XPtrrstan::stan_fit_base fit_ptr(stan_model_holder* smh) {
344 : return Rcpp::XPtrrstan::stan_fit_base(new rstan::stan_fit(model_ptr(smh), smh->random_seed_), true);
345 : }
346 :
347 : std::string model_name(stan_model_holder* smh) {
348 : return model_ptr(smh).get()->model_name();
349 : }
350 :
351 : RCPP_MODULE(stan_fit4model242412b94d4b_efb77423d7adb44255913eac3d9377e8_mod){
352 : Rcpp::class_<stan_model_holder>(“stan_fit4model242412b94d4b_efb77423d7adb44255913eac3d9377e8”)
353 : .constructor<rstan::io::rlist_ref_var_context, unsigned int>()
354 : .method(“model_ptr”, &model_ptr)
355 : .method(“fit_ptr”, &fit_ptr)
356 : .method(“model_name”, &model_name)
357 : ;
358 : }
359 :
360 :
361 : // declarations
362 : extern “C” {
363 : SEXP file24241c9c430e( ) ;
364 : }
365 :
366 : // definition
367 :
368 : SEXP file24241c9c430e( ){
369 : return Rcpp::wrap(“efb77423d7adb44255913eac3d9377e8”);
370 : }
371 :
372 :
make cmd is
make -f “C:/PROGRA~1/R/R-40~1.3/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-40~1.3/share/make/winshlib.mk” CXX=’(CXX14) (CXX14STD)’ CXXFLAGS=’(CXX14FLAGS)' CXXPICFLAGS='(CXX14PICFLAGS)’ SHLIB_LDFLAGS=’(SHLIB_CXX14LDFLAGS)' SHLIB_LD='(SHLIB_CXX14LD)’ SHLIB=“file24241c9c430e.dll” WIN=64 TCLBIN=64 OBJECTS=“file24241c9c430e.o”

make would use
“C:/rtools40/mingw64/bin/“g++ -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.3/include” -DNDEBUG -I"C:/Users/JoJo/Documents/R/win-library/4.0/Rcpp/include/” -I"C:/Users/JoJo/Documents/R/win-library/4.0/RcppEigen/include/" -I"C:/Users/JoJo/Documents/R/win-library/4.0/RcppEigen/include/unsupported" -I"C:/Users/JoJo/Documents/R/win-library/4.0/BH/include" -I"C:/Users/JoJo/Documents/R/win-library/4.0/StanHeaders/include/src/" -I"C:/Users/JoJo/Documents/R/win-library/4.0/StanHeaders/include/" -I"C:/Users/JoJo/Documents/R/win-library/4.0/RcppParallel/include/" -I"C:/Users/JoJo/Documents/R/win-library/4.0/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include “C:/Users/JoJo/Documents/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp” -std=c++1y -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c file24241c9c430e.cpp -o file24241c9c430e.o
if test “zfile24241c9c430e.o” != “z”; then
if test -e “file24241c9c430e-win.def”; then
echo “C:/rtools40/mingw64/bin/“g++ -shared -s -static-libgcc -o file24241c9c430e.dll file24241c9c430e-win.def file24241c9c430e.o “C:/Users/JoJo/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a” -L"C:/Users/JoJo/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/JoJo/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ;
“C:/rtools40/mingw64/bin/“g++ -shared -s -static-libgcc -o file24241c9c430e.dll file24241c9c430e-win.def file24241c9c430e.o “C:/Users/JoJo/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a” -L"C:/Users/JoJo/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/JoJo/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
“C:/rtools40/mingw64/bin/“nm file24241c9c430e.o | sed -n ‘s/^.* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed 's/[^ ][^ ]*/”&”/g’ >> tmp.def;
echo “C:/rtools40/mingw64/bin/“g++ -shared -s -static-libgcc -o file24241c9c430e.dll tmp.def file24241c9c430e.o “C:/Users/JoJo/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a” -L"C:/Users/JoJo/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/JoJo/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ;
“C:/rtools40/mingw64/bin/“g++ -shared -s -static-libgcc -o file24241c9c430e.dll tmp.def file24241c9c430e.o “C:/Users/JoJo/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a” -L"C:/Users/JoJo/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/JoJo/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/PROGRA~1/R/R-40~1.3/bin/x64" -lR ;
rm -f tmp.def;
fi \

CHECKING DATA AND PREPROCESSING FOR MODEL ‘efb77423d7adb44255913eac3d9377e8’ NOW.

COMPILING MODEL ‘efb77423d7adb44255913eac3d9377e8’ NOW.

STARTING SAMPLER FOR MODEL ‘efb77423d7adb44255913eac3d9377e8’ NOW.

SAMPLING FOR MODEL ‘efb77423d7adb44255913eac3d9377e8’ NOW (CHAIN 1).
Chain 1:
Chain 1: Gradient evaluation took 0 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1:
Chain 1:
Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup)
Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup)
Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup)
Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%] (Sampling)
Chain 1:
Chain 1: Elapsed Time: 0.011 seconds (Warm-up)
Chain 1: 0.014 seconds (Sampling)
Chain 1: 0.025 seconds (Total)
Chain 1:
Inference for Stan model: efb77423d7adb44255913eac3d9377e8.
1 chains, each with iter=2000; warmup=1000; thin=1;
post-warmup draws per chain=1000, total post-warmup draws=1000.

  mean se_mean   sd  2.5%   25%   50%   75% 97.5% n_eff Rhat

y -0.04 0.06 1.02 -2.00 -0.71 -0.04 0.67 2.04 343 1.00
lp__ -0.52 0.03 0.74 -2.71 -0.70 -0.25 -0.05 0.00 494 1.01

Samples were drawn using NUTS(diag_e) at Fri Nov 06 10:01:28 2020.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found

Hmm, I’ve never seen this before (RStan working but brms crashing). Sorry for the trouble!

The next test is to get the model and data that brms creates and try running that through rstan.

Can you try the following:

library(brms)
library(rstan)

stancode = make_stancode(formula = time | cens(censored) ~ age * sex + disease 
    + (1 + age|patient), cores = 4,
    data = kidney, family = lognormal(),
    prior = c(set_prior("normal(0,5)", class = "b"),
              set_prior("cauchy(0,2)", class = "sd"),
              set_prior("lkj(2)", class = "cor")))

standata = make_standata(formula = time | cens(censored) ~ age * sex + disease 
    + (1 + age|patient), cores = 4,
    data = kidney, family = lognormal(),
    prior = c(set_prior("normal(0,5)", class = "b"),
              set_prior("cauchy(0,2)", class = "sd"),
              set_prior("lkj(2)", class = "cor")))

mod = stan(model_code=stancode,data=standata)

hola,

I wanna install rstan in windows, the only problem is that I don´t have my Rtools in the default location I have to put it somewhere else, so I put in makevar.win the new location and follow the instalion steps but when I call the library or run stan I got the following error:

Error in cleanup_makevar(old) : 
  argument "RMU" is missing, with no default
In addition: Warning messages:
1: In readLines(file, warn = TRUE) :
  incomplete final line found on '\\home.org.aalto.fi\alonzoi1\data\Documents\school.stan'
2: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'Z:/rtools40/usr/mingw_/bin/g++' not found
3: In readLines(file.path(makevar_files)) :
  incomplete final line found on '//home.org.aalto.fi/alonzoi1/data/Documents/.R/Makevars.win'
4: In readLines(old_path) :
  incomplete final line found on '//home.org.aalto.fi/alonzoi1/data/Documents/.R/Makevars.win'

@andrjohns do you know how an I fix this error?

RStan on windows currently doesn’t like a Makevars.win file and throws that error. You have a couple of options here. First, you can use the .Renviron and/or .Rprofile files to configure where R looks for compilers and remove your Makevars file.

Instead (or in addition to), you can downgrade your withr package to 2.20, which should work:

devtools::install_version("withr",version="2.20")

Then restart R and try again.

Also, add a blank line to the end of your Makevars.win file and stan code to remove the incomplete final line errors

1 Like

So the first parts of the stan code run just fine. Then when I try to run the mod code it crashed on me twice. Then when I got it to not crash it gave me this again:

Error in unserialize(socklist[[n]]) : error reading from connection
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found
Error in serialize(data, node$con, xdr = FALSE) :
error writing to connection

Can you post the output from:

Sys.getenv("PATH")
Sys.getenv("BINPREF")
readLines("~/.R/Makevars.win")
readLines("~/.Rprofile")
readLines("~/.Renviron")
devtools::session_info("rstan")

I know you’ve already posted it, but I just need to double-check that nothing’s changed

Sys.getenv(“PATH”)
[1] “C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.3\bin\x64;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel® Management Engine Components\IPT;C:\Program Files\Intel\Intel® Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;D:\JRE\bin;C:\Users\JoJo\AppData\Local\Microsoft\WindowsApps”
Sys.getenv(“BINPREF”)
[1] “”
readLines("~/.R/Makevars.win")
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/JoJo/Documents/.R/Makevars.win’: No such file or directory
readLines("~/.Rprofile")
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/JoJo/Documents/.Rprofile’: No such file or directory
readLines("~/.Renviron")
[1] “PATH=”{RTOOLS40_HOME}\\usr\\bin;{PATH}""
devtools::session_info(“rstan”)

  • Session info ---------------------------------------------------------------------------------------------------------------------------
    setting value
    version R version 4.0.3 (2020-10-10)
    os Windows 10 x64
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate English_United States.1252
    ctype English_United States.1252
    tz America/New_York
    date 2020-11-09

  • Packages -------------------------------------------------------------------------------------------------------------------------------
    ! package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3)
    backports 1.1.10 2020-09-15 [1] CRAN (R 4.0.3)
    BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.3)
    callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.3)
    checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.3)
    cli 2.1.0 2020-10-12 [1] CRAN (R 4.0.3)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.3)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.3)
    curl 4.3 2019-12-02 [1] CRAN (R 4.0.3)
    desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.3)
    digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3)
    ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.3)
    evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3)
    fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.3)
    farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.3)
    ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.3)
    glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.3)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.3)
    inline 0.3.16 2020-09-06 [1] CRAN (R 4.0.3)
    isoband 0.2.2 2020-06-20 [1] CRAN (R 4.0.3)
    jsonlite 1.7.1 2020-09-07 [1] CRAN (R 4.0.3)
    labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.3)
    lattice 0.20-41 2020-04-02 [2] CRAN (R 4.0.3)
    lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.3)
    loo 2.3.1 2020-07-14 [1] CRAN (R 4.0.3)
    magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.3)
    MASS 7.3-53 2020-09-09 [2] CRAN (R 4.0.3)
    Matrix 1.2-18 2019-11-27 [2] CRAN (R 4.0.3)
    matrixStats 0.57.0 2020-09-25 [1] CRAN (R 4.0.3)
    mgcv 1.8-33 2020-08-27 [2] CRAN (R 4.0.3)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.3)
    nlme 3.1-149 2020-08-23 [2] CRAN (R 4.0.3)
    pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.3)
    pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.3)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3)
    pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.3)
    praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.3)
    prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.3)
    processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.3)
    ps 1.4.0 2020-10-07 [1] CRAN (R 4.0.3)
    R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.3)
    Rcpp * 1.0.5 2020-07-06 [1] CRAN (R 4.0.3)
    RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.3)
    D RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.3)
    rlang 0.4.8 2020-10-08 [1] CRAN (R 4.0.3)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.3)
    rstan * 2.21.2 2020-07-27 [1] CRAN (R 4.0.3)
    rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.3)
    scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.3)
    StanHeaders * 2.21.0-6 2020-08-16 [1] CRAN (R 4.0.3)
    testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.3)
    tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.3)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.3)
    V8 3.3.1 2020-10-26 [1] CRAN (R 4.0.3)
    vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.3)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.3)
    withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.3)

[1] C:/Users/JoJo/Documents/R/win-library/4.0
[2] C:/Program Files/R/R-4.0.3/library

D – DLL MD5 mismatch, broken installation.

Thanks! I’ll have to call in for help with debugging this.

@bgoodri This user is getting crashes in RStan. The example model compiles & samples, but more complex models like this brms model crash.

A quick config summary:

  • No Makevars.win or .Rprofile
  • RStan, StanHeaders, and inline all up-to-date
  • make statement in this post

Do you know if there is any updates on this, I have not seen any replies? Thanks

Hi @andrjohns I am trying to install rstan in windows, and after following all the procedures in the stan repository, but I still have some problems. When I ran

example(stan_model, package = “rstan”, run.dontrun = TRUE)

I got this error:

Error in compileCode(f, code, language = language, verbose = verbose) :
cc1plus.exe: fatal error: \home.org.aalto.fi/alonzoi1/data/Documents/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: file20869442cca.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 in advance.

 sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Yep that error happens when your R package directory is on a network drive, you need to move your packages to a location on your local computer

thanks for your reply, but I don´t understand, both R and Rtools are in the window default C: directory…How do I do that?

While the R and RStudio programs themselves are installed on the C:/ drive, your R packages (rstan, etc.) are installed in your ‘Home’ directory, which the error message above indicates is on an external network drive (\home.org.aalto.fi/alonzoi1/data/Documents). You need to move your R packages to a folder on your local C:/ Drive.

I posted some instructions on how to do this over in this post. Those instructions were putting the R packages in the C:/Users/R folder, so just change that path to wherever you want to move your R packages to

2 Likes

Thank you!