Specifying compiler in RStudio on Mac

Hi-

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.

That looks like it. /usr/local/bin comes first in the working version, whereas /usr/bin comes first in the nonworking one. Thanks!

This topic was automatically closed 7 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.