Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install rJava for use with 64bit R on a 64 bit Windows computer?

Tags:

I installed iplots and rjava packages. When I do this library(iplots), I get the following error. I do have JDK installed on my pc.

Loading required package: rJava Error : .onLoad failed in loadNamespace() for 'rJava', details: call: fun(libname, pkgname) error: JAVA_HOME cannot be determined from the Registry 

Error: package ‘rJava’ could not be loaded

like image 237
george willy Avatar asked Feb 02 '12 21:02

george willy


People also ask

Where does Java 64 bit install?

All of the 64-bit programs are installed in the Program Files directory, easily accessible using Windows Explorer. Look for the Java directory within Program Files and you will find all of the 64-bit Java packages that are installed located there. They will be listed by name.


2 Answers

The error is telling you that there is no entry in your Registry that tells R where Java is located on your machine. Either your registry is corrupt, but more likely you haven't installed Java. You can install either the Java Runtime Environment or the Java Development Kit.

(You can download Java here.)

If you installed Java, try reinstalling it. This should put the entries back in your Registry.

If that doesn't work, you can start looking at exactly where R is looking for your Registry entries. The function that rJava uses to find Java is in the rJava:::.onLoad function. Within that function there is a subfunction called find.java. I copy the contents here:

    find.java <- function() {         for (root in c("HLM", "HCU")) for (key in c("Software\\JavaSoft\\Java Runtime Environment",              "Software\\JavaSoft\\Java Development Kit")) {             hive <- try(utils::readRegistry(key, root, 2),                silent = TRUE)             if (!inherits(hive, "try-error"))                return(hive)         }         hive     } 

Copy and paste this into your R window, and then run it find.java(). rJava is looking for an entry for JavaHome. If that isn't listed, then it is missing from your registry.

You could also manually set the directory of your Java location by setting it before loading the library:

Sys.setenv(JAVA_HOME='C:\\Your\\Java\\Directory') library(rJava) 
like image 193
nograpes Avatar answered Oct 21 '22 21:10

nograpes


If like me you do not have admin rights to install 64-bit Java, just open 32-bit R and it should work ok on your 64 bit PC as part of the problem seems to be the rJava library function calls embedded Java functions/routines, which may only have being designed for 32-bit interface with Excel/Windows and possibly too large a task at the time to change everything.

like image 21
hopethishelps Avatar answered Oct 21 '22 20:10

hopethishelps