Potential Problems with rstan and /or brms packages in R 4.0.2

Thanks. Yes it indeed seems to be the same issue.

Thanks Paul and Andrjohns for replying. So, in the mean time, the solution is to use rstan version 2.19.3? Indeed I have been using version 2.21.1

Yes, reverting back to rstan 2.19.3 will fix the problem. As of now, rstan 2.21.1 is only available as source on CRAN so when you just uninstall rstan and install it again but then refuse to compile from source, it will give you rstan 2.19.3 directly. In a few days rstan 2.21.1 will also be available as compiled package in which case the approach above does not work anymore and you have to go for:

packageurl <- "http://cran.r-project.org/src/contrib/Archive/rstan/rstan_2.19.3.tar.gz"
install.packages(packageurl, repos = NULL, type = "source")
3 Likes

I do confirm you that reverting back to rstan 2.19.3 solved the issue. Thank you very much Paul. And have a good day.

1 Like

It would be nice to be notified when rstan is fixed, but I don’t know where to look for it.
Apparently, it seems that lots of topics have been opened, all of them pointing to the same problem, which makes it very difficult to follow.

2 Likes

This is where to look at:

Thank you for the suggestion. I have similar issues with brms after updating r and want to try reverting back to an earlier version of rstan. However, when I run the code you suggested, I get the following error. Any ideas of how to fix it? I tried googling but haven’t found a solution. Thanks!

Installing package into ‘C:/Users/Daphne Liu/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL ‘http://cran.r-project.org/src/contrib/Archive/rstan/rstan_2.19.3.tar.gz
Content type ‘application/x-gzip’ length 922337 bytes (900 KB)
downloaded 900 KB

  • installing source package ‘rstan’ …
    ** package ‘rstan’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs

*** arch - i386

C:/Rtools/mingw_64/bin/g++.exe -m32 -std=c++1y -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG -I"…/inst/include" -I"." -I"C:/Users/Daphne Liu/Documents/R/win-library/4.0/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I’C:/Users/Daphne Liu/Documents/R/win-library/4.0/Rcpp/include’ -I’C:/Users/Daphne Liu/Documents/R/win-library/4.0/RcppEigen/include’ -I’C:/Users/Daphne Liu/Documents/R/win-library/4.0/BH/include’ -I’C:/Users/Daphne Liu/Documents/R/win-library/4.0/StanHeaders/include’ -O3 -march=native -c sparse_extractors.cpp -o sparse_extractors.o
sh: C:/Rtools/mingw_64/bin/g++.exe: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.2/etc/i386/Makeconf:229: sparse_extractors.o] Error 127
ERROR: compilation failed for package ‘rstan’

  • removing ‘C:/Users/Daphne Liu/Documents/R/win-library/4.0/rstan’
  • restoring previous ‘C:/Users/Daphne Liu/Documents/R/win-library/4.0/rstan’
    Warning in install.packages :
    installation of package ‘C:/Users/DAPHNE~1/AppData/Local/Temp/RtmpCmzG1g/downloaded_packages/rstan_2.19.3.tar.gz’ had non-zero exit status

sh: C:/Rtools/mingw_64/bin/g++.exe: No such file or directory

It means that your file g++.exe doesn’t exist in this folder, you need to find where it was installed in your system.

I use Rtools40
https://cran.r-project.org/bin/windows/Rtools/
and the g++.exe file can be found in the directory

C:\rtools40\mingw64\bin

Maybe you could try to install Rtools40?

Hello,
I was having the same problem with Rstan version 2.12.2 not compiling and tried reverting to 2.19.3 with the code you sent but it gives me this error:

packageurl <- “http://cran.r-project.org/src/contrib/Archive/rstan/rstan_2.19.3.tar.gz

install.packages(packageurl, repos = NULL, type = “source”)
trying URL ‘http://cran.r-project.org/src/contrib/Archive/rstan/rstan_2.19.3.tar.gz
Content type ‘application/x-gzip’ length 922337 bytes (900 KB)
==================================================
downloaded 900 KB

  • installing source package ‘rstan’ …
    ** package ‘rstan’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs

clang++ -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"…/inst/include" -I"." -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include" -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c chains.cpp -o chains.o

clang: warning: no such sysroot directory: ‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk’ [-Wmissing-sysroot]
In file included from chains.cpp:19:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/arr/err/check_nonzero_size.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/meta.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/arr/meta/get.hpp:4:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/include/c++/v1/cstdlib:85:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/include/c++/v1/stdlib.h:93:15: fatal error: ‘stdlib.h’ file not found
#include_next <stdlib.h>
^~~~~~~~~~

clang++ -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"…/inst/include" -I"." -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include" -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c init.cpp -o init.o

clang: warning: no such sysroot directory: ‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk’ [-Wmissing-sysroot]
In file included from init.cpp:25:
In file included from /Library/Frameworks/R.framework/Resources/include/R.h:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/include/c++/v1/cstdlib:85:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/…/include/c++/v1/stdlib.h:93:15: fatal error: ‘stdlib.h’ file not found
#include_next <stdlib.h>
^~~~~~~~~~
1 error generated.

make: *** [init.o] Error 1
make: *** Waiting for unfinished jobs…
1 error generated.
make: *** [chains.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rstan’
    Warning in install.packages :
    installation of package ‘/var/folders/_v/_dp_x44j2_gb3fg47_bgdrxw0000gn/T//Rtmp0q7TYZ/downloaded_packages/rstan_2.19.3.tar.gz’ had non-zero exit status

I’m using macOS Catalina version 10.15.6
brms version: 2.13.5
R version: 3.6.0

Thanks

Hello, I’m also having problems rolling back:

g++ -m64 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -I"…/inst/include" -I"." -I"D:/Documents/R/win-library/3.6/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"D:/Documents/R/win-library/3.6/Rcpp/include" -I"D:/Documents/R/win-library/3.6/RcppEigen/include" -I"D:/Documents/R/win-library/3.6/BH/include" -I"D:/Documents/R/win-library/3.6/StanHeaders/include" -O3 -march=native -c sparse_extractors.cpp -o sparse_extractors.o
sparse_extractors.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in

^
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: sparse_extractors.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘D:/Documents/R/win-library/3.6/rstan’
  • restoring previous ‘D:/Documents/R/win-library/3.6/rstan’
    Warning in install.packages :
    installation of package ‘C:/Users/Alasdair/AppData/Local/Temp/RtmpYjZ4zU/downloaded_packages/rstan_2.19.3.tar.gz’ had non-zero exit status

This error implies that the right compiler (64-bit) isn’t being found. To help figure out why, can you post the outputs from:

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

Thanks for your help! I have everything nicely set up and working on my work Imac (which i’ve been working on all summer) and Win10 laptop. Now trying to get set up for the autumn on my home desktop, and running into all sorts of problems with the new versions of R, RTools, etc.

Sys.getenv(“PATH”)
[1] “C:\rtools\usr\bin;C:\Program Files\R\R-3.6.3\bin\x64;C:\Rtools\bin;c:\Rtools\bin;c:\Rtools\mingw_32\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Windows\System32\OpenSSH\;c:\Users\Alasdair\AppData\Local\enthought\Canopy\User\Scripts;C:\Users\Alasdair\AppData\Local\Enthought\Canopy\User;C:\Users\Alasdair\AppData\Local\Enthought\Canopy\User\Scripts;C:\Users\Alasdair\AppData\Local\Microsoft\WindowsApps;C:\Users\Alasdair\AppData\Local\GitHubDesktop\bin”
Sys.getenv(“BINPREF”)
[1] “”
readLines("~/.R/Makevars.win")
[1] “”
[2] “CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2”
[3] “”
[4] “CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2”
[5] “”
[6] “CXX14FLAGS=-O3 -march=native”
[7] “CXX14 = g++ -m$(WIN) -std=c++1y”
[8] “CXX11FLAGS=-O3 -march=native”
[9] “”
[10] “CXX14FLAGS=-O3 -march=corei7 -mtune=corei7”
[11] “CXX14 = (BINPREF)g++ -m(WIN) -std=c++1y”
[12] “CXX11FLAGS=-O3 -march=corei7 -mtune=corei7”
readLines("~/.Rprofile")
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘D:/Documents/.Rprofile’: No such file or directory
readLines("~/.Renviron")
[1] “PATH=“C:\rtools\usr\bin;${PATH}””

Alright, the first step is to tell R where to look for the compiler. You can do this by setting the BINPREF environment variable using a .Rprofile file. You can create this through R by running:

cat('Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")',
    file = file.path(Sys.getenv("HOME"), ".Rprofile"), 
    sep = "\n", append = FALSE)

Then restart R and test that your toolchain is working by trying to compile a package from source:

install.packages("jsonlite",type="source")

Looks like that worked?

What should I try next?

And, while i have your attention, is there a good, up-to-date guide about how to get things working on Win10, and what versions of are required? (All my problems started when I foolishly decided to update R to the current version!)

I’m going to be teaching Statistical Rethinking this academic term, and providing tech support to students is going to be a nightmare. [Grumble grumble about Covid closing the computer labs…]

Sorry I missed your reply. If that works you should be good to go to install/run RStan.

As for an up-to-date guide, the Install Instructions on the RStan wiki are the closest thing: https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started

But they could do with some coverage of common issues and how to resolve them. It’s been on my to-do-list for a little while, but I’ll try and get them updated over the next few days

Great and thanks!

Yes, I know about that Installation Guide. It usually works well. I have a hunch that there are some issues with some combination of the latest rStan, R, RTools and brms all not playing nice together!

I suspect it may be a good idea to avoid the latest version of R for a while, and advise my students to install v3.6.x, etc. (at least on Windows10).

Anyway, you’ve been extremely helpful. If I ever run into you in person, I owe you a beer/coffee.

No worries! Yeah, while the getting started is helpful for the basic setup, it could really use a section for dealing with common issues that people come across.

Are there any updates on this topic? I am teaching two stats classes where I introduce them to Bayesian using brms and it has been a complete nightmare trying to get things to work (I’ve never had this issue before). Many students are having to give up. This is happening on both Macs and PCs, with an incredibly diverse set of error messages showing up. My own combination of operating system, R, brms, Xcode and rStan is sort of working, but only in RStudio (not the default R interface) and despite throwing an error message on every attempt to compile (it produces results despite the error). Does anyone have a comprehensive idea of how to get all the levels to play nice with each other? Or do we know what changed this summer that made all hell break lose? Thanks for any thoughts or guidance.

1 Like

I’ve updated the Windows installation instructions to avoid most of the common issues (seems to have the done the trick, given the reduction in support posts recently). I haven’t had time to properly run through the Mac install instructions yet (since I need to set up VMs to test properly), but will be getting through that in the next couple of weeks.

In the interim, R4.0 tends to play best with rstan across both pre-Catalina and Catalina OSes. Stephen Martin had a great writeup of installation/setup instructions in this post as well: R 4.0, rstan, and you

1 Like

Thank you so much!! I’ll point the students to these instructions and with a little luck things will settle down. Thank you for all you do. Cheers, Emily