4

I have been trying to get brms/rstan to work on my system with limited luck. I have R 4.2 and am using R studio. I originally started doing this in R, because I couldn't get any Bayes packages to work in Python and I (it seems incorrectly) thought it would be easier to set up in R.

I was watching a video on how to do regression with brms (https://www.youtube.com/watch?v=-1Hob2qpyeY), so installed brms and bayesplot. RStudio told me to install Rtools so I did. I was able to run an lm, but then with a brm I was unable to run a model. I uninstalled all packages and attempted to trouble shoot, and have followed several help posts at this point with no success.

I thought maybe there was an issue because R is installed to the C:\Program Files and I don't have write access (not an administrator) so I tried to change the default library using https://www.accelebrate.com/library/how-to-articles/r-rstudio-library

I tried following https://learnb4ss.github.io/learnB4SS/articles/install-brms.html but the "Configure C++" part did not give the expected result (https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows unable to install json)

I reinstalled RTools. I tried looking at this post, but cannot figure out what the second directory I need is https://github.com/metrumresearchgroup/mrgsolve/issues/160 "Note there are two directories that you need at the front of the path." and the output for sys.getenv is massive. My Rtools is C:\rtools40

Sys.getenv("PATH")

1 "c:\rtools42\x86_64-w64-mingw32.static.posix\bin;c:\rtools42\usr\bin;C:\rtools42\usr\bin;C:\Program Files\R\R-4.2.0\bin\x64;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet;C:\Program Files (x86)\dotnet;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Users\XXXXXXXX\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\XXXXXXXX\AppData\Local\Programs\Python\Python310;C:\Users\XXXXXXXX\AppData\Local\Microsoft\WindowsApps;C:\Users\XXXXXXXX\AppData\Local\Programs\Microsoft VS Code\bin;C:\msys64\mingw64\bin;C:\Program Files\R\R-4.2.0"

Image of Environment variables Image of Path variables

I tried running the example model again at this point

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

and he mess below is what I got. I am out of ideas on what I need to do to get any type of bayesian model to work (Between Python and R, I have been watching videos and reading stackoverflow and github for days and I can't get any installs to run), please help!

The final error code:

Compilation ERROR, function(s)/method(s) not created!

Error in compileCode(f, code, language = language, verbose = verbose) : sh: line 1: C:/rtools42/usr/mingw_64/bin/g++: No such file or directorymake: *** [C:/PROGRA~1/R/R-42~1.0/etc/x64/Makeconf:259: fileeaa4c76716d.o] Error 127

The gigantic mess of everything that wasn't "program source" that was spat out

Blockquote example(stan_model, package = "rstan", run.dontrun = TRUE) Loading required package: StanHeaders Loading required package: ggplot2 rstan (Version 2.21.5, GitRev: 2e1f913d3ca3) For execution on a local, multicore CPU with excess RAM we recommend calling options(mc.cores = parallel::detectCores()). To avoid recompilation of unchanged Stan programs, we recommend calling rstan_options(auto_write = TRUE) Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file 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'. COMPILING THE C++ CODE FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW. OS: x86_64, mingw32; rstan: 2.21.5; Rcpp: 1.0.8.3; inline: 0.3.19

setting environment variables: LOCAL_LIBS = "C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/rstan/lib/x64/libStanServices.a" -L"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/RcppParallel/lib/x64" -ltbb PKG_CPPFLAGS = -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/Rcpp/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/RcppEigen/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/RcppEigen/include/unsupported" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/BH/include" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/StanHeaders/include/src/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/StanHeaders/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/RcppParallel/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include "C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp" -std=c++1y . . . Blockquote make cmd is make -f "C:/PROGRA~1/R/R-42~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-42~1.0/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="fileeaa4c76716d.dll" WIN=64 TCLBIN= OBJECTS="fileeaa4c76716d.o"

make would use C:/rtools42/usr/mingw_64/bin/g++ -std=gnu++14 -I"C:/PROGRA~1/R/R-42~1.0/include" -DNDEBUG -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/Rcpp/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/RcppEigen/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/RcppEigen/include/unsupported" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/BH/include" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/StanHeaders/include/src/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/StanHeaders/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/RcppParallel/include/" -I"C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include "C:/Users/XXXXXX/AppData/Local/R/win-library/4.2/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp" -std=c++1y -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include" -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c fileeaa4c76716d.cpp -o fileeaa4c76716d.o if test "zfileeaa4c76716d.o" != "z"; then
if test -e "fileeaa4c76716d-win.def"; then
echo C:/rtools42/usr/mingw_64/bin/g++ -shared -s -static-libgcc -o fileeaa4c76716d.dll fileeaa4c76716d-win.def fileeaa4c76716d.o -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ;
C:/rtools42/usr/mingw_64/bin/g++ -shared -s -static-libgcc -o fileeaa4c76716d.dll fileeaa4c76716d-win.def fileeaa4c76716d.o -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
C:/rtools42/usr/mingw_64/bin/nm fileeaa4c76716d.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g' >> tmp.def;
echo C:/rtools42/usr/mingw_64/bin/g++ -shared -s -static-libgcc -o fileeaa4c76716d.dll tmp.def fileeaa4c76716d.o -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ;
C:/rtools42/usr/mingw_64/bin/g++ -shared -s -static-libgcc -o fileeaa4c76716d.dll tmp.def fileeaa4c76716d.o -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"c:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ;
rm -f tmp.def;
fi
fi ERROR(s) during compilation: source code errors or compiler configuration errors! Compilation ERROR, function(s)/method(s) not created! Error in compileCode(f, code, language = language, verbose = verbose) : sh: line 1: C:/rtools42/usr/mingw_64/bin/g++: No such file or directorymake: *** [C:/PROGRA~1/R/R-42~1.0/etc/x64/Makeconf:259: fileeaa4c76716d.o] Error 127

Beth
  • 41
  • 2

1 Answers1

5

This happens since R version 4.2. You could either try to revert to an older R version or try:

remove.packages(c("StanHeaders", "rstan"))

install.packages(
  "StanHeaders",
  repos = c(
    "https://mc-stan.org/r-packages/",
    getOption("repos")
  )
)

install.packages(
  "rstan",
  repos = c(
    "https://mc-stan.org/r-packages/",
    getOption("repos")
  )
)

source: https://discourse.mc-stan.org/t/rstan-fails-to-build-example-model/27248

Carlos Luis Rivera
  • 3,108
  • 18
  • 45
REmpre
  • 51
  • 2