Problems with C++ compiler toolchain for R on Mac in newer Rstudio versions.

I recently came across an issue with the C++ toolchain on Mac that I assume exists since Ventura (Mac 13.x). Up until Rstudio version 2022.02.4-500, this issue never made problems for me in R, but it appeared once I upgraded to more recent versions, specifically 2022.12.0-353. In that later version, I was not able to compile most R packages and also no Stan models anymore when using R through Rstudio.

After playing around for some time, I now unstand it and want to share it with the community in case other's run into the same problem.

The reason turned out to be a change in how the PATH environment variable is handled in Rstudio. Previously (version 2022.02.4-500 or earlier), my PATH as seen via Sys.getenv() in R was

/usr/bin:/bin:/usr/sbin:/sbin:/Library/Developer/CommandLineTools/usr/bin:/usr/local/bin:/opt/homebrew/bin/gfortran:/Library/TeX/texbin:/Library/Apple/usr/bin:/opt/local/bin:/Applications/RStudio.app/Contents/MacOS/postback

In particular, /usr/bin:/bin:/usr/sbin:/sbin was at the front.

In the newer version of Rstudio (e.g., version 2022.12.0-353), my PATH was now

/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Developer/CommandLineTools/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin/gfortran:/Library/TeX/texbin:/Library/Apple/usr/bin:/Users/paul.buerkner/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/Resources/app/bin/postback

so no more /usr/bin:/bin:/usr/sbin:/sbin at the front but rather behind /Library/Developer/CommandLineTools/usr/bin.

Once /Library/Developer/CommandLineTools/usr/bin was removed from the PATH entirely or /usr/bin:/bin:/usr/sbin:/sbin was put to the front, things worked correctly. I don't know why /Library/Developer/CommandLineTools/usr/bin needs to be in the PATH but it seems Mac itself wants it to be there (it is added in /private/etc/paths, a file that does not want to be changed easily).

Perhaps future versions of Rstudio could add /usr/bin:/bin:/usr/sbin:/sbin back again at the start of the PATH just to be safe?

1 Like

Great trace. Could you file an issue on the git repo? (I'll also flag for the inhouse guys).

1 Like

Thanks. Opened an issue at Problems with C++ compiler toolchain for R on Mac in newer Rstudio versions · Issue #12529 · rstudio/rstudio · GitHub

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.