I've got gcc and ancillary tools installed via homebrew on my system, which works fine in standalone R, but when I try to install packages in RStudio, it uses the XCode version, which often leads to errors since it doesn't link the the right libraries, etc. For example, within RStudio:
> system("gcc --version")
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
But within standalone R:
> system("gcc --version")
gcc (Homebrew GCC 9.2.0_3) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I've tried setting it in ~/.R/Makevars, but RStudio doesn't seem to use this file.
Any idea how I can get RStudio to use the right compiler?
Ok, I've noticed that in my Rstudio projects using renv the compiler gets set, correctly, to the system gcc:
* Project '~/projects/fangblennies/plagiotremus/plagiotremus' loaded. [renv 0.11.0]
Warning message:
Project requested R version '3.6.2' but '4.0.2' is currently being used
> system("gcc --version")
gcc (Homebrew GCC 9.2.0_3) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
What is the output of Sys.getenv("PATH")? It sounds like it's probably different in these two cases, and so the PATH entry from which gcc is resolved differs in each case.
If you're setting the PATH within (for example) your shell's startup profile, those sorts of changes won't be visible when launching R via RStudio. In that case, you might want to set PATH in your ~/.Rprofile or ~/.Renviron.