tags:

views:

598

answers:

4

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

+1  A: 

After editing your post for readability / formatting it seems that you have no Java system in your path. I don't use the OS you're trying to use this on, but on mine rJava only works if I also install a Java Run-Time Environment or, better still, a Java SDK.

Note that the package clearly lists

SystemRequirements: java

and that the rJava site clearly states the following

Installation

First, make sure you have JDK 1.4 or higher installed (some platforms require hgher version see R Wiki). On unix systems make sure that R was configured with Java support. If not, you can re-configure R by using R CMD javareconf (you may have to prepend sudo or run it as root depending on your installation - see R-ext manual A.2.2 for details). On Windows Java is detected at run-time from the registry.

rJava can be installed as any other R package from CRAN using install.packages('rJava'). See the files section in the left menu for development versions.

JRI is only compiled if supported, i.e. if R was configured as a framework or with --enable-R-shlib.

so I think we have a few smoking guns pointing the same way.

Dirk Eddelbuettel
I have added an edit to my original question.
Farrel
+2  A: 

Following up on some of Dirk's sage advice:

  • Your path should probably say C:\Program Files\Java\jre6\bin\ (remove "client").
  • Your path should also have C:\Program Files\R\R-2.10.1\bin\. You don't need that explicit reference to the rJava libs. I would also then remove C:\Program Files\R from the path.
  • Lastly, confirm that Java is accessible by either going to your command prompt and typing java -version, or from within R by typing system("java -version").
  • If you install the SDK, then you will also want a system variable JAVA_HOME which in my case points to C:\Sun\SDK\.
Shane
I am busy going through your suggestions. I will give you feedback when I get to see if it works or not.
Farrel
It worked. Thanks.
Farrel
A: 

Hi,

I have encountered the same problem (Win 7 64 bit with 32 bit R 2.10.1).
R as well as Java are in the Path but ...

system("java -version")

java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b22, mixed mode)

library(rJava)

Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared library 'C:/R/R2101/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'

Do you have any other idea?

Veit
I followed the advice of Shane and it worked. My path is 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\bin;C:\Program Files\Java\jre6\binAnd here is what I get from R> system("java -version")java version "1.6.0_18"Java(TM) SE Runtime Environment (build 1.6.0_18-b07)Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
Farrel
If you look at the error message, it shows: "C:/R/R2101/library". I'm guessing that you have R incorrectly set in your path. It should likely be something more like: C:\Program Files\R\R-2.10.1\bin\.
Shane
no ... the path is fine
Veit
A: 

I installed java jre/jdk now many times and finaly installed the older version 1.6.0_17 which is now located at "C:\Program Files\Java\jre6\bin". Now after all if I call 'java -version' within R i can see that R is looking for Java at the old path which is now wrong. The question is: Why is R looking for Java at the wrong path even so the windows path is set correctly?

On windows shell:
$>set
[..]
OS=Windows_NT
Path=C:\Program Files\Java\jre6\bin;
[..]

$> java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

within R:
$>system("java -version")
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.cfg'

Veit
1) You need to restart R in order for the path change to take effect. 2) Maybe you have duplicate entires in your path? 3) This is not an answer; please start a new question.
Shane
1) I did 2) I dont see any duplicat's 3) ok ... I did setup a new question for it. Can I remove this one anyhow?
Veit
@Viet: Yes. You should have a delete link under the answer (err...you might need more rep for that...).
Shane