Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load rJava because cannot load a shared library

Tags:

java

path

r

I have been struggling to load the rJava package in R.

I get the following messages

> library(rJava)
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared library \
     'C:/PROGRA~1/R/R-210~1.1/library/rJava/libs/rJava.dll':
  LoadLibrary failure:  The specified module could not be found.


Error : .onLoad failed in 'loadNamespace' for 'rJava'
Error: package/namespace load failed for 'rJava'

I have tried so many solutions that they are all bamboozeled in my head. At some point I even got

> R Console: Rgui.exe - System Error The
> program can't start because
> MSVCR71.dll is is missing from your
> computer. Try reinstalling the program
> to fix this problem.

I made sure everything I could think of was on the path

> C:\Program Files\R\Rtools\bin;C:\Program Files\R\Rtools\perl\bin;
  C:\Program Files\R\Rtools\MinGW\bin;%SystemRoot%\system32;
  %SystemRoot%;%SystemRoot%\System32\Wbem;
  %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
  C:\Program Files\QuickTime\QTSystem\;
  C:\Program Files\R\R-2.10.1\library\rJava\libs\;
  C:\Program Files\R;C:\Program Files\Java\jre6\bin\client  

What should I try next?

I am running R version 2.10.1 (2009-12-14) and I have also tried R version 2.10.1 Patched (2010-03-03 r51210). It is on a Windows machine running windows 7 enterprise

like image 583
Farrel Avatar asked Mar 08 '10 02:03

Farrel


2 Answers

System information: R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)

I encountered this same problem. I was able to solve the issue with one line of code into the command window obtained from this website.

Sys.setenv(JAVA_HOME='C:\Program Files\Java\jre7')

Note that I used this particular line because I was on a 64 bit system. See website for 32-bit example.

like image 101
John Thompson Avatar answered Oct 02 '22 21:10

John Thompson


If you have read this threat and neither of the suggestions above has worked so far, then it might be worth trying one further:

  • Windows 7
  • R version 2.12.1 (2010-12-16) 64-bit
  • Java(TM) SE Runtime Environment (build 1.6.0_23-b05), Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)

    JAVA_HOME=C:\Program Files\Java\jre6\bin\

    Path= ...;C:\Program Files\Java\jre6\bin\server\;C:\Program Files\R\R-2.12.1\bin\x64\

The thing that finally solved my problem was to explicitly add \server\ to the PATH variable.

like image 40
Hans Christian Avatar answered Oct 02 '22 20:10

Hans Christian