Using the rJava package on Win7 64 bit with R

error: package or namespace load failed for ‘rjava’:
r xlsx package java_home cannot be determined from the registry
package rjava was built under r version 3.5 3
rjava error
error: package or namespace load failed for mailr
java_home cannot be determined from the registry xlconnect
sys.setenv java_home r
java 7 download 64-bit

I'm trying to install rJava on a computer with Win 7 64 bit. When I run

install.packages("rJava")

everything seems to be fine:

Installing package(s) into ‘C:/Users/djq/Documents/R/win-library/2.13’
(as ‘lib’ is unspecified)
trying URL 'http://software.rc.fas.harvard.edu/mirrors/R/bin/windows/contrib/2.13/rJava_0.9-1.zip'
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
    C:\TEMP\RtmpW2eAUw\downloaded_packages

but when I tried to load the library library(rJava) 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 rJava fine. Is the problem just that rJava 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():

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

$arch
[1] "x86_64"

$os
[1] "mingw32"

$system
[1] "x86_64, mingw32"

$status
[1] ""

$major
[1] "2"

$minor
[1] "13.1"

$year
[1] "2011"

$month
[1] "07"

$day
[1] "08"

$`svn rev`
[1] "56322"

$language
[1] "R"

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

Using the rJava package on Win7 64 bit with R, I faced same issue with Using the rJava package on Win7 64 bit with R, Java > Sys.getenv("JAVA_HOME") [1] "C:\\Program  To use rjava package for R (64-bit) version download and install Java SE Development Kit 8 for Windows x64 from here. Similarly for R (32-bit) version download and install Java SE Development Kit 8 for Windows x86 from here. To build or check R packages with multi-arch you need to install both Java For Windows x64 as well as Java for Windows x86.

Getting rJava to work depends heavily on your computers configuration:

  1. You have to use the same 32bit or 64bit version for both: R and JDK/JRE. A mixture of this will never work (at least for me).
  2. If you use 64bit version make sure, that you do not set JAVA_HOME as a enviorment variable. If this variable is set, rJava will not work for whatever reason (at least for me). You can check easily within R is JAVA_HOME is set with

    Sys.getenv("JAVA_HOME")
    

If you need to have JAVA_HOME set (e.g. you need it for maven or something else), you could deactivate it within your R-session with the following code before loading rJava:

if (Sys.getenv("JAVA_HOME")!="")
  Sys.setenv(JAVA_HOME="")
library(rJava)

This should do the trick in most cases. Furthermore this will fix issue Using the rJava package on Win7 64 bit with R, too. I borrowed the idea of unsetting the enviorment variable from R: rJava package install failing.

Using the rJava package on Win7 64 bit with R · Issue #85 · s-u , How to load the {rJava} package after the error "JAVA_HOME cannot be This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). easily effect Windows 7 users, since they might have installed a version of Java that is  Using the rJava package on Win7 64 bit with R #85. Closed englianhu opened this issue Aug 26, 2016 · 2 comments Closed Using the rJava package on Win7 64 bit with R

For me, setting JAVA_HOME did the trick (instead of unsetting, as in another answer given here). Either in Windows:

set JAVA_HOME="C:\Program Files\Java\jre7\"

Or inside R:

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

But what's probably the best solution (since rJava 0.9-4) is overriding within R the Windows JAVA_HOME setting altogether:

options(java.home="C:\\Program Files\\Java\\jre7\\")
library(rJava)

rJava, This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit This problem can easily effect Windows 7 users, since they might  Voici quelques conseils rapides sur la façon de démarrer avec R + rJava sur Windows 7 64 bits. Il y a plusieurs possibilités, mais la plupart ont des défauts fatals. Voici ce qui a fonctionné pour moi: Ajouter jvm.dll à votre PATH. rJava, le pont R -> Java, aura besoin de jvm.dll, mais R aura du mal à trouver cette DLL. Il réside dans

The last question has an easy answer:

> .Machine$sizeof.pointer
[1] 8

Meaning I am running R64. If I were running 32 bit R it would return 4. Just because you are running a 64 bit OS does not mean you will be running 64 bit R, and from the error message it appears you are not.

EDIT: If the package has binaries, then they are in separate directories. The specifics will depend on the OS. Notice that your LoadLibrary error occurred when it attempted to find the dll in ...rJava/libs/x64/... On my MacOS system the ...rJava/libs/...` folder has 3 subdirectories: i386, ppc, and x86_64. (The ppc files are obviously useless baggage.)

How to load the {rJava} package after the error , Check whether R is 32/64 bit with sessionInfo() . Download Java JDK for 32/64 bit. For 64-bit I Install rJava with install.packages("rJava") . Error: package/namespace load failed for 'rJava' j'ai installé le Java JRE (en essayant les versions 32 et 64 bits) et le JDK (en utilisant les versions 32 et 64 bits). Ma version R est R version 2.13.1 (2011-07-08) et j'utilise RStudio. si j'essaie d'utiliser 32 bits R, je peux charger rJava très bien.

Sorry for necro. I have too run into the same issue and found out that rJava expects JAVA_HOME to point to JRE. If you have JDK installed, most probably your JAVA_HOME points to JDK. My quick solution:

Sys.setenv(JAVA_HOME=paste(Sys.getenv("JAVA_HOME"), "jre", sep="\\"))

Installing rJava on Windows 10, Using this package, data of population viability analysis (PVA) generated with the correctly with R. Make sure to install a 64-bit JDK if you are using a 64-bit version of R. A typical installation path for Java-based packages like glmulti in a Windows 7 tutorial), verify on Command Prompt (Win + r, “cmd”, Enter): echo  Runtime). For 64-bit Revolution R you need to make sure that you have a 64-bit version of Java installed. Make sure that the Java 'CLASSPATH' variable is set properly. For the 64-bit version of the JDK, this is typically set to something like the following(on Windows): 'C:\Program Files\Java\jdk1.7.0_02\jre\lib\ext' Check your system PATH settings.

vortexR, In case you tried loading a package that depends on the {rJava} This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have  Install rJava with install.packages("rJava"). Set your JAVA_HOME environment with Sys.setenv(JAVA_HOME="C:/Program Files/Java/jdk-10.0.1/") so that it points to your specific (64-bit in my case) folder that contains the jdk .

How to load the {rJava} package after the error , I'm having a problem with the rJava package. I can download it to my machine (​Win 7 64-bit) but when I try to load the package into R (2.15.1, This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using. Note that it is necessary to ‘manually download and install’ the 64 bit version of JAVA.

R help - rJava install, String)" # Use method "concat" to connect character string. this section: - Windows 7: x86_64-w64-mingw32/x64 (64-bit) - R: version 3.0.1 In Java: Oracle SUN  Using the rJava package on Win7 64 bit with R. 929. Failed to load the JNI shared Library (JDK) 966. Can't start Eclipse - Java was started but returned exit code=13

Comments
  • Can you please paste the results of R.Version() to your question? I have just installed the 64bit version of rJava using the exact method you describe in your question. My guess is that your version of R is 32 bit.
  • pls share your ans how you solved it.
  • Adding a comment here as it may help someone the task of going through the whole solution list. If you get the above error, check if your Java is in Program Files or Program Files (x86). Add path to windows as the accepted answer says. If Program Files (x86), it means you have 32-bit version, follow the link sites.google.com/site/rforfishandwildlifegrads/home/week_2/….
  • Rather than leaving the second argument blank, you can just do install.packages('rJava', repos='http://www.rforge.net/').
  • As pointed out in the answer by @user2161065, loading rJava requires removing the JAVA_HOME variable
  • Although all this might be needed, even after doing this I had to unset JAVA_HOME as suggested by @user2161065
  • +1 Adding ...\jre\bin\server to path fixed it for me
  • Where can we find this "Windows PATH" variable?
  • The previous solutions did not work until I got rid of JAVA_HOME. This is key.
  • This JAVA_HOME issue should be reported to rJava as a bug.
  • This really did the trick for me : if (Sys.getenv("JAVA_HOME")!="") Sys.setenv(JAVA_HOME="") library(rJava) Thanks @user2161065
  • adding that script to remove the JAVA_HOME var worked for me!