11

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

3
  • Do you have a Java Run-Time Environment (JRE) or even a Java SDK on your system? Commented Mar 8, 2010 at 3:04
  • At some stage (but relatively early) I went to java.com/en and downloaded java from there. I went back to that website now and used their Java test and received the following iformation: Vendor: Sun Microsystems Inc. Version: Java 6 Update 18 Operating System: Windows 7 6.1 Architecture: x86. The program seem to be sitting in C:\Program Files\Java\jre6. I do not really know how paths work. Does one have to specify down to the actual subdirectory or can I just point in the general vicinity and the software will know to look in the subdirectories. Thanks for reformatting my post. Commented Mar 8, 2010 at 3:43
  • Proper installation of a given the 'component' usually takes care of adjusting the PATH e.g. that is what R does. The rJava text I quoted talks about getting Java info from the registry, so I presume something is borked on your box. Commented Mar 8, 2010 at 4:16

6 Answers 6

14

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Same here, ` \server` was needed. The way I found out was by running library("rJava") from R GUI, which printed jvm.dll is missing. Emacs prints entirely different error message. After I added ` \server` to path, both emacs/ess and gui versions worked ok.
I can concur. Thank you for putting this answer here.
5

For what it's worth, putting C:\Program Files\Java\jre6\bin\[server] in my PATH worked for me. It seems the rJava module could jot find jvm.dll there.

Here are the versions of R and Java that I'm using (on 64-bit Windows 7).

Java:

java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)

R:

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-mingw32/x64 (64-bit)

Comments

5

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.

Comments

4

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\.

1 Comment

I am busy going through your suggestions. I will give you feedback when I get to see if it works or not.
3

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.

Comments

1

I had a similar error and had to do an additional fix: Setting the R path explicitly to ...bin\x64, and also being consistent in using x64 Java and R.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.