Dealing with R 4.0

Right, thanks, I overlooked that.


example(cxxfunction, package = "inline", run.dontrun = TRUE)




If I run that call Ben I get:

ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'

And sure,


is what I have.


I added this to my .R/Makevars

FC = /usr/local/gfortran/bin/gfortran
FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm

@torkar: But does Stan work?

Yes, except for when using cores=4, but that’s an RStudio bug which there’s a workaround for :)

Daniel - I don’t know if you have solved this problem already, but since I came across your post when looking for a solution to exactly the same issue, I thought I’d share what worked for me: putting the following in your Makevars file. Hope it solves your problem.

CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

1 Like

bumping thread

bumping again

You can probably ask @martinmodrak to pin it!

There’s a lot of results when googling which seem to deal with the OSX side of the issue. I don’t use OSX but the underlying issues is described at and .

The issue is that somehow a math.h is ending up in the compiler search path before the C++ math.h. The solution will be to avoid this.

An example of how this can happen is if you include say, glibc before the c++ stdlib.

I’ve installed R-4.0.0 and R-3.6.3 on Linux-Ubuntu 20.04 following the guide:
Where I changed the curl download from ubuntu-1604 to ubuntu-2004. I can start both within Rstudio and with R-4.0.0 in Rstudio I ran the advised code in OP but ended up installing some extra packages with the Terminal in order to get shinystan to work. Rstan works indeed, thank you!

Question: If i now start R-3.6.3 in Rstudio and run install.packages(‘rstan’, dependencies = TRUE) again, would you expect any complications? It is ok if Rstan just works in R4.0.0, but I could work more flexible if it works in multiple versions. However I am hesitant to just try it and risk breaking what is currently working.

On linux, you should be okay back to R 3.4.x and even previous versions if your C++ compiler supports the C++14 standard (although you may have to adjust the required version of R in the DESCRIPTION file).

That was wonderful Ben. Works like a charm, thank you for sharing!

Is this installation guide (install.txt) somewhere online? I found it very good and the official Rstan getting started does not seem to have this info about R 4.0.0 problems.

It’s not, no. It was just a document I sent to some students/faculty prior to a Stan seminar. I wouldn’t mind if the Stan team wanted to use it somewhere though.

1 Like

I can update RStan’s getting started guide with this info. I’ll have a first run at adding this in and ping you for a quick review to see if I’ve missed anything (if that’s ok).

@bgoodri Any preference on whether this goes into the ‘RStan Getting Started’ page or gets added as separate ‘RStan & R4.0’ page?


I think I have a more updated one: install.txt (783.5 KB)

The main story though - Is the pre-R4.0 instructions should be fine on < 4.0 setups. After R 4.0, Rtools40 should be used on windows, and Xcode (only) should be used on osx. Any previous configurations should be stripped out (in .Rprofile, .Renviron, and R/Makevars{.win}). They can be recreated with optimization options only (and the Rstudio parallel fix for OSX); no need for paths.


@Stephen_Martin, would it be possible to provide some optimization options for default compilers in Win/Lin/OS X, so new people simply can cut and paste into their Makevars?