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.