Cannot run models after updating brms and rstan

Hello,

After updating to brms 2.13.3 and rstan 2.21.1, I have found that I am no longer able to run models using “brm” command. When I run the code, it begins with “Compiling Stan program…” and then ceases running. There are no error messages accompanying this.

Here is an easy code to run:

n = 100 
Var1 = sample(c(0,1),n,replace=TRUE)
value =  sample(c(0,1),n,replace=TRUE)

df <- data.frame(value = value, Var1 = Var1)

m1 <- brm(value ~  Var1, data = df)

My computer specs are:
Operating System: Windows 10
R version 4.0.2
Rstudio version 1.3.959
brms version 2.13.3

Thanks for any advice you can give!

Did you update Rtools? If not, that could be giving you troubles (it happened to me after transitioning to R 4.0.2)

I actually installed Rtools just today, so that should be fine. It might be relevant to note that this Windows computer I am using is new, and I have previously only used R on Apple products, so it is possible that I am missing something important (permissions or similar problems). However, I have noticed no other issues with R except this problem with running the model.

see this post for how to use rstan 2.19.3 instead, which might fix this problem.

1 Like

We need the result of

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

in order to see what the problem is, particularly the part under the line that says “Compilation argument:”.

1 Like

@julianquandt, I can’t speak for @Limulus, but I was having the same issue (also having just installed brms and rtools on a new machine) and this worked for me! Thanks for the link.

1 Like

Hi, unfortunately, none of the links appeared to help my situation. When running:

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

It returns hundreds of lines of errors. I cannot make heads or tails of the output. The last error I receive is:

Error in compileCode(f, code, language = language, verbose = verbose) :

Compilation ERROR, function(s)/method(s) not created! C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file32c4623019d3.o:file32c4623019d3.cpp:(.text+0x71c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)’

C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file32c4623019d3.o:file32c4623019d3.cpp:(.text+0x1327): undefined reference to `rstan::stan_fit::stan_fit(SEXPREC*, int)’

C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file32c4623019d3.o:file32c4623019d3.cpp:(.text+0x75e): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)’

C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file32c4623019d3.o:file32c4623019d3.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler

In addition: Warning message:
In file.remove(c(unprocessed, processed)) :
cannot remove file ‘C:\Users\danie\AppData\Local\Temp\RtmpCqQWMk\file32c42763515.stan’, reason ‘No such file or directory’

I believe the error goes much deeper, and I am thinking about simply uninstalling R and reinstalling to try to rebuild it.

That won’t help. Try setting

    StanHeaders_pkg_libs <- system.file("libs", .Platform$r_arch,
                                        package = "StanHeaders", mustWork = TRUE)
    RcppParallel_pkg_libs <- system.file("lib", .Platform$r_arch,
                                         package = "RcppParallel", mustWork = TRUE)
    rstan_StanServices <- system.file("lib", .Platform$r_arch, "libStanServices.a",
                                      package = "rstan", mustWork = TRUE)

  PL <- paste(rcpp_pkg_libs,
              rstan_StanServices,
              paste0("-L", shQuote(StanHeaders_pkg_libs)),
              "-lStanHeaders",
              paste0("-L", shQuote(RcppParallel_pkg_libs)),
              tbb_libs)
Sys.setenv(LOCAL_LIBS = PL)

before calling Stan.

When I run that code I get the error:

Error in paste(rcpp_pkg_libs, rstan_StanServices, paste0("-L", shQuote(StanHeaders_pkg_libs)), :
object ‘rcpp_pkg_libs’ not found

Nevermind what I said before. We have temporary binaries now that you can install at

Hi,

I am facing this issue after downloading R v 4.0 to my new laptop. I tried the troubleshooting suggested by @bgoodri in the last message in this thread. Got this error:

package ‘rstan’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘rstan’
Warning in install.packages :
problem copying C:\Users\Dr.Meghana\Documents\R\win-library\4.0\00LOCK\rstan\libs\x64\rstan.dll    to C:\Users\Dr.Meghana\Documents\R\win-library\4.0\rstan\libs\x64\rstan.dll: Permission    denied
Warning in install.packages :
restored ‘rstan’

None of the other suggestions seem to work for me. Any help will be much appreciated.

Thanks,
Meghna

Try

remove.packages("rstan")
file.remove(".RData")

and if that doesn’t work, manually delete the folder C:\Users\Dr.Meghana\Documents\R\win-library\4.0\rstan using Windows Explorer. Then, in a clean R session, try installing rstan again.

Hi Ben,

Writing with an update. I had managed to get brms up and running after following your instructions. However, today the same problem has reappeared. This time, the troubleshooting tips in this thread did not work for me. What worked for me was to install an older version of brms (v2.13.0).

Best,
Meghna

2 Likes

I have this exact same problem. Brms just stops after ‘Compiling Stan program…’.

I am running Windows 7, R version is 4.0.2, RTools version is 4.0 (its path contains no spaces), brms version is 2.13.5, and rstan version is 2.21.2. RStudio version is 1.3.1073.

And unlike meghs, I do not know how to manually install an earlier version of brms to fix this.

bump

UPDATE: I figured out how to install older versions of packages. Going back to version 2.13.0 of brms did not help. Neither did reverting to brms 2.12.0. I also tried downgrading R itself from 4.0.2 to 3.6.3 (the last version where everything still worked) and RTools to 3.5.0, all of which availed me naught. Now brms just will not work, no matter what I do. Once the model is (presumably) compiled and sampling is due to start, brms just aborts without any warning or error message.

It isn’t going to have anything to do with brms. Can you do

remotes::install_github("bgoodri/inline")
example(stan_model, package = "rstan", run.dontrun = TRUE)

and post what the error message is?

There are almost 400 lines of cryptic messages. The final error message is:

Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found
2: In file(con, "r") :
  cannot open file 'file126827444826.cpp.err.txt': No such file or directory

That first warning is safe to ignore, for the error can you run:

remotes::install_github("bgoodri/inline")

And try the model again?

Skipping install of 'inline' from a github remote, the SHA1 (f80c7f99) has not changed since last install.
  Use `force = TRUE` to force installation

I ran the same command with force = TRUE, then called require(inline) before trying to fit the model again. It continues to crash at the same stage, but now it also produces textual output:

make cmd is
  make -f "C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-40~1.2/share/make/winshlib.mk" -f "C:\Users\juho\AppData\Local\Temp\Rtmp6JqhlS\Makevars1e6c4f3a532c" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file1e6c6aa82693.dll" WIN=64 TCLBIN=64 OBJECTS="file1e6c6aa82693.o"

make would use
g++ -m64 -std=c++1y -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG   -I"C:/Users/juho/Documents/R/win-library/4.0/Rcpp/include/"  -I"C:/Users/juho/Documents/R/win-library/4.0/RcppEigen/include/"  -I"C:/Users/juho/Documents/R/win-library/4.0/RcppEigen/include/unsupported"  -I"C:/Users/juho/Documents/R/win-library/4.0/BH/include" -I"C:/Users/juho/Documents/R/win-library/4.0/StanHeaders/include/src/"  -I"C:/Users/juho/Documents/R/win-library/4.0/StanHeaders/include/"  -I"C:/Users/juho/Documents/R/win-library/4.0/RcppParallel/include/"  -I"C:/Users/juho/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/juho/Documents/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp"  -std=c++1y         -O3 -c file1e6c6aa82693.cpp -o file1e6c6aa82693.o
if test "zfile1e6c6aa82693.o" != "z"; then \
  if test -e "file1e6c6aa82693-win.def"; then \
    echo g++ -m64 -std=c++1y -shared -s -static-libgcc -o file1e6c6aa82693.dll file1e6c6aa82693-win.def file1e6c6aa82693.o   "C:/Users/juho/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/juho/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/juho/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
    g++ -m64 -std=c++1y -shared -s -static-libgcc -o file1e6c6aa82693.dll file1e6c6aa82693-win.def file1e6c6aa82693.o   "C:/Users/juho/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/juho/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/juho/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    "C:/rtools40/mingw64/bin/"nm file1e6c6aa82693.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g'  >> tmp.def; \
    echo g++ -m64 -std=c++1y -shared -s -static-libgcc -o file1e6c6aa82693.dll tmp.def file1e6c6aa82693.o   "C:/Users/juho/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/juho/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/juho/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
    g++ -m64 -std=c++1y -shared -s -static-libgcc -o file1e6c6aa82693.dll tmp.def file1e6c6aa82693.o   "C:/Users/juho/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/juho/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/juho/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi