Why Rstudio compiler looking for R headers in the wrong include directories?

49 views Asked by At

The compiler wants to include R.h header file. These header files come installed with R, so obviously, the include is in the R installation dir.

But while trying to install a package, the compiler is looking at the wrong paths (though I added the path in my env vars):

g++ -std=gnu++17  -I"/include" -DNDEBUG  -I'~/R/win-library/3.6/sp/include'   -I"C:/rtools43/x86_64-w64-mingw32.static.posix/include" -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c dummy.cc -o dummy.o
gcc  -I"/include" -DNDEBUG  -I'~/R/win-library/3.6/sp/include' -I"C:/rtools43/x86_64-w64-mingw32.static.posix/include" -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c init.c -o init.o
init.c:1:10: fatal error: R.h: No such file or directory
    1 | #include <R.h>
      |          ^~~~~
compilation terminated.

Is there any way to make the compiler look at the include path specified in my env vars?


/s/ is a dependency for rgeos package:

install.packages("~/R/win-library/3.6/rgeos_0.6-4.tar.gz", repos = NULL, type = "source")

I had to transfer R headers from R install dir to /sp/ so the compiler can find them. I shouldn't have to do that...

1

There are 1 answers

0
MFIHRI On

Turned out it was indeed a cluttered environment variables and installation system. Here's what I have done and hopefully it helps someone:

  1. Uninstalled the old Rtools (kept Rtools43
  2. Modified past refs in environment variables (reset R_HOME and R_LIBS_USER):
R_HOME        C:\Program Files\R\R-4.3.1  (it was pointing to old 3.6.2 version
R_LIBS_USER   C:\Users\Your-USERNAME\Documents\R\win-library\4.3 (was pointing to 3.6

Note: Above entries are NOT under the path, which might skip you. This will affect your compiler, even if your path is pointing correctly. Unfortunately, your program compiler will not report this issue. it might show you the correct path but it doesn't mean it was not redirected by an old RSTUDIO refs to another path.>

  1. Modifying the path:

C:\rtools43\usr\bin

(instead of just C:\rtools43

  1. Modifying ~/.Renviron (tilde is whatever the output of):
Sys.getenv("HOME")

add:

PATH="${RTOOLS43_HOME}\usr\bin;${PATH}"

and save.

Reboot your system. If RTOOLS43_HOME entry doesn't show on the environment variables, just add it explicitly:

RTOOLS43_HOME  C:\rtools43

Note, above entry is NOT to be put in the path. I added it to both system and user vars just in case the latter doesn't have some permissions.

On Rstudio, under Tools/Install Packages/Install to Library:

should have as default entry the value of R_LIBS_USER from above.

Finally, the output of .libPaths() should only include reachable and active/used paths for a)libraries install dir and b)R dir.

.libPaths()

[1] "C:/Users/YOUR-USERNAME/Documents/R/win-library/4.3" "C:/Program Files/R/R-4.3.1/library"   

Above paths are specific to Windows 10. Yours will be dependent on your system.

If you did EVERYTHING as suggested here. You can now run a successful install such as:

> install.packages("~/R/win-library/4.3/rgeos_0.6-4.tar.gz", repos = NULL, type = "source")

Without the compiler breaking on ya. Good luck and don't forget to thumb UP this answer if you found it useful. So it will be recommended to others. Thanks in advance!