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 was at the front.
In the newer version of Rstudio (e.g., version 2022.12.0-353), my PATH was now
so no more
/usr/bin:/bin:/usr/sbin:/sbin at the front but rather behind
/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?