9

I am trying to use XLConnect library in R. If I execute

library(XLConnect)

I get the following error message:

JAVA_HOME cannot be determined from the Registry

To resolve this problem I set first the JAVA_HOME variable:

Sys.setenv(JAVA_HOME='C:/Program Files (x86)/Java/jre1.8.0_65')
library(XLConnect)

It looks like it helps me to come further but then I get another problem:

unable to load shared object 'C:/Program Files/R/R-3.2.2/library/rJava/libs/x64/rJava.dll'

It wonder why R cannot load rJava.dll. At least this file is located in the folder where R searches for it:

C:\Program Files\R\R-3.2.2\library\rJava\libs\x64

ADDED

Please note that the rJava.dll file exists and it is located there, where R is searching for it. I guess that the problem is in incompatibility between 32bit and 64bit versions. I assume that because R complains:

% 1 is not a valid Win32 application

Well, why do R expect it to be a Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder withx64` in the name (so, I assume it is also a 64bit version).

Roman
  • 124,451
  • 167
  • 349
  • 456
  • 1
    Create and place it the folder where it is looking for it? – tchakravarty Nov 11 '15 at 17:19
  • Am i missing something? Those paths look the same to me. – MrFlick Nov 11 '15 at 17:27
  • Are you sure the java is the right one for your OS/r version ie 32 vs 64bit? http://stackoverflow.com/questions/7019912/using-the-rjava-package-on-win7-64-bit-with-r and some other links in comment http://stackoverflow.com/questions/29186040/convert-a-csv-to-excel-without-using-xlsx-package#comment46587465_29186040 – user20650 Nov 11 '15 at 17:36
  • @user20650, I have 64bit OS and my Java is for 64bit. So, it is consistent. However, in R error message I see: `% 1 is not a valid Win32 application`. Of course it is not, because it is a Win64 application. So, the question is why R expects a Win32 application and how to change it? – Roman Nov 12 '15 at 08:37
  • 1
    I'd recommend using `readxl` instead. The package includes C and C++ libraries, and it is simpler and probably faster to use. Get the excel data out of there as quickly as possible, then do post-processing in R: this is what `readxl` does well. – Jack Wasey Nov 14 '15 at 16:08
  • 1
    @Roman: you said you had 64bits OS and Java 64bits but what about R ? Are you using a 32bits or 64 bits version ? – etienne Nov 17 '15 at 16:30
  • ...and you've updated all of your packages and checked that the path is correct? – Andy Clifton Nov 20 '15 at 00:36

2 Answers2

4

I faced the same issue . Please locate jvm.dll should be in (your JRE version could be different )

C:\Program Files (x86)\Java\jre1.8.0_65\bin\client

or

C:\Program Files (x86)\Java\jre1.8.0_65\bin\server

add this path to your windows system path and you are good to go .but keep in mind the version of jre and R should be consistent,if your java is in Program Files its 64 bit so launch from 64 bit R if its in Program Files (x86)its 32 bit so use 32 bit R

like in my case it showed error in 64 bit enter image description here

but worked perfectly in 32 bit enter image description here

Bg1850
  • 3,032
  • 2
  • 16
  • 30
3

You did use / instead of \.

Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre1.8.0_65') 
library(XLConnect)

I am using UNIX. Therefore I cannot test it by myself but your path might be wrong as well.

According to this post you can search it by using this:

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
}

credit goes to @nograpes for the function and this article for helping me giving you the answer.

Community
  • 1
  • 1
zipp
  • 1,116
  • 13
  • 27