Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid "cannot find -lR" for R Package installation on windows

Tags:

windows

r

I want to install packages from source:

Setting up the environmental variables:

Sys.setenv(BINPREF = "C:/PROGRA~1/R/Rtools/mingw_64/bin/")
Sys.setenv(BINPREF64 = "C:/PROGRA~1/R/Rtools/mingw_64/bin/")
Sys.setenv(PATH = "C:/PROGRA~1/R/R-3.4.2/bin/x64/;C:/PROGRA~1/R/Rtools/bin/;C:/PROGRA~1/R/Rtools/mingw_64/bin/")

Installing any package from source results in "cannot find -lR" error:

install.packages("later")

Error message:

C:/PROGRA~1/R/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o
later.dll tmp.def RcppExports.o callback_registry.o debug.o init.o
later.o later_posix.o later_win32.o timer_posix.o timestamp_unix.o
timestamp_win32.o tinycthread.o
-Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-34~1.2/bin/i386 -lR C:/PROGRA~1/R/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe:
skipping incompatible C:/PROGRA~1/R/R-34~1.2/bin/i386/R.dll when searching for -lR
C:/PROGRA~1/R/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe:
skipping incompatible C:/PROGRA~1/R/R-34~1.2/bin/i386/R.dll when searching for -lR
C:/PROGRA~1/R/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lR collect2.exe: error: ld returned 1 exit status no DLL
was created
ERROR: compilation failed for package 'later'

As indicated here: https://community.rstudio.com/t/installing-source-package-failure-to-link/14775 it might be the case that for some reason a 32-bit file is linked on my 64-bit machine. But i dont see any Errors in my pathes. (In the past, the install from source worked well).

Sys.info()
             sysname              release              version             nodename              machine                login                 user       effective_user 
           "Windows" "Server >= 2012 x64"         "build 9200"         "YY"             "x86-64"            "XX"            "XX"            "XX" 

Session info:

Version:1.0 StartHTML:0000000107 EndHTML:0000001240 StartFragment:0000000127 EndFragment:0000001222
sessionInfo() R version 3.4.2 (2017-09-28) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows Server >= 2012 x64 (build 9200)

Rstudio 1.1.383

Also posted here: https://community.rstudio.com/t/how-to-avoid-cannot-find-lr-for-r-package-installation-on-windows/49425.

Related:

  • https://support.bioconductor.org/p/11509/ (But my sessionInfo does not Point to any Linux Version).
like image 253
Tlatwork Avatar asked Nov 07 '22 10:11

Tlatwork


1 Answers

You are making three mistakes:

  1. You should not install rtools under program files or any other path with a space.
  2. You are using BINPREF wrong, causing the 64-bit toolchain to be used on 32-bit.
  3. The mingw gcc dirs should not be on the PATH. Only the bin dir (bash and make) should be.

Recommended setup:

It is highly recommended to install rtools in the default location C:\Rtools\. This is the only configuration that is widely tested.

In this case you only need to make put C:\Rtools\bin is on the PATH in order to compile packages. R will automatically use the correct compilers on 32-bit and 64-bit.

With non-default Rtools location:

If you really must install rtools in a non standard location, you can set BINPREF to a pattern that includes $(WIN) that gets expanded to the correct path for example like so:

Sys.setenv(BINPREF="C:/YourRtoolsPath/mingw_$(WIN)/bin/")

When make invokes the compiler, $(WIN) gets substituted by either 32 or 64 which should then resolve to the correct path of the respective toolchain.

like image 116
Jeroen Ooms Avatar answered Nov 15 '22 07:11

Jeroen Ooms