djq djq - 1 month ago 7x
R Question

Using the rJava package on Win7 64 bit with R

I'm trying to install

on a computer with Win 7 64 bit. When I run


everything seems to be fine:

Installing package(s) into ‘C:/Users/djq/Documents/R/win-library/2.13’
(as ‘lib’ is unspecified)
trying URL ''
Content type 'application/zip' length 654936 bytes (639 Kb)
opened URL
downloaded 639 Kb

package 'rJava' successfully unpacked and MD5 sums checked

The downloaded packages are in

but when I tried to load the library
I get the following error:

Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/me/Documents/R/win-library/2.13/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.

Error: package/namespace load failed for 'rJava'

I have installed the Java JRE (trying both 32 and 64 bit versions) and the JDK (using both 32 and 64 bit). My R version is
R version 2.13.1 (2011-07-08)
and I'm using RStudio.

If I try using 32 bit R, I can load
fine. Is the problem just that
does not run in R 64 bit? How can I tell if a package is just for 32 instead of 64?

edit: just posted

> R.Version()
[1] "x86_64-pc-mingw32"

[1] "x86_64"

[1] "mingw32"

[1] "x86_64, mingw32"

[1] ""

[1] "2"

[1] "13.1"

[1] "2011"

[1] "07"

[1] "08"

$`svn rev`
[1] "56322"

[1] "R"

[1] "R version 2.13.1 (2011-07-08)"


(Note: many of folks in other answers/comments have said to remove JAVA_HOME, so consider that. I have not revisited this issue recently to know if all the steps below are still necessary.)

Here is some quick advice on how to get up and running with R + rJava on Windows 7 64bit. There are several possibilities, but most have fatal flaws. Here is what worked for me:

Add jvm.dll to your PATH

rJava, the R<->Java bridge, will need jvm.dll, but R will have trouble finding that DLL. It resides in a folder like

C:\Program Files\Java\jdk1.6.0_25\jre\bin\server


C:\Program Files\Java\jre6\jre\bin\client

Wherever yours is, add that directory to your windows PATH variable. (Windows -> "Path" -> "Edit environment variables to for your account" -> PATH -> edit the value.)

You may already have Java on your PATH. If so you should find the client/server directory in the same Java "home" dir as the one already on your PATH.

To be safe, make sure your architectures match.If you have Java in Program Files, it is 64-bit, so you ought to run R64. If you have Java in Program Files (x86), that's 32-bit, so you use plain 32-bit R.

Re-launch R from the Windows Menu

If R is running, quit.

From the Start Menu , Start R / RGUI, RStudio. This is very important, to make R pick up your PATH changes.

Install rJava 0.9.2.

Earlier versions do not work! Mirrors are not up-to-date, so go to the source at Note the advice there

“Please use


to install.”

That is almost correct. This actually works:

install.packages('rJava', .libPaths()[1], '')

Watch the punctuation! The mysterious “.libPaths()[1],” just tells R to install the package in the primary library directory. For some reason, leaving the value blank doesn’t work, even though it should default.