Unable to load rJava on R

2020-01-24 12:30发布

I wish to load rJava in R x64 3.1.2. OS- Windows 8.1 64 bit

Though installation seems to work fine:

  > install.packages("rJava")
    Installing package into ‘C:/Users/sony/Documents/R/win-library/3.1’
    (as ‘lib’ is unspecified)
    --- Please select a CRAN mirror for use in this session ---
    trying URL 'http://cran.utstat.utoronto.ca/bin/windows/contrib/3.1/rJava_0.9-6.zip'
    Content type 'application/zip' length 758898 bytes (741 Kb)
    opened URL
    downloaded 741 Kb

package ‘rJava’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\sony\AppData\Local\Temp\RtmpamYUH7\downloaded_packages

I get an error while loading the package:

library(rJava)
Error in get(Info[i, 1], envir = env) : 
  lazy-load database 'C:/Users/sony/Documents/R/win-library/3.1/rJava/R/rJava.rdb' is corrupt
In addition: Warning message:
In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1
Error: package or namespace load failed for ‘rJava’

I know that I am working on R-64 bit and at same time the environment variable Path is set to:

C:\Program Files\Java\jdk1.7.0_51\bin;C:\Program Files\Java\jre7\bin\server;

also, so the Java version is 64 bit too. I don't understand the reason behind the error.

On manually setting through R:

options(java.home="C:\\Program Files\\Java\\jdk1.7.0_51\\bin")
library(rJava)

I get this error:

enter image description here

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/sony/Documents/R/win-library/3.1/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  The specified module could not be found.

Error: package or namespace load failed for ‘rJava’

Any advice? The error seems to have cropped up after I uninstalled some old version of Java.

OTHERS: Also just to add, I do not set JAVA_HOME as a environment variable.

Uninstalling and Reinstalling R also doesn't seem to fix the problem.

Removing older java versions is too of no help.

标签: r rjava
8条回答
冷血范
2楼-- · 2020-01-24 12:35

Faced similar error message.

Tried a few steps listed here.

  1. Set Env. Variable, JAVA_HOME. => Didn't work.
  2. Tried to install rJava +> Didn't work Steps 3,4,5 worked..
  3. Updated my Java 64 bit version 8.xx (latest available)
  4. install.packages(rJava) ==> Success
  5. install.packages(RWeka) ==> Success
查看更多
男人必须洒脱
3楼-- · 2020-01-24 12:39

Use:

Sys.setenv(JAVA_HOME='...path to JRE...')

e.g.

Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jdk1.7.0_51\\jre')

Your environment variable is wrong.

查看更多
Melony?
4楼-- · 2020-01-24 12:41

I got a similar error:

> library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/program files/R/R-3.1.2/library/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  The specified module could not be found.

My JAVA_HOME was pointing to JDK, rather than JRE.

> Sys.getenv("JAVA_HOME")
[1] "c:\\java\\jdk1.7.0_55"
> Sys.setenv(JAVA_HOME="c:\\java\\jdk1.7.0_55\\jre")

I could now load rJava and xlsx in R.

查看更多
Summer. ? 凉城
5楼-- · 2020-01-24 12:41

It is probably the issue with the setting with the JAVA_HOME pointer. In case you do not have JDK but JRE, here is you might have to do: Sys.setenv(JAVA_HOME='C:\Program Files\Java\jre1.8.0_161')

Remember to change the numbers after "jre" based on what you have on your computer. Here is a link that explains the difference between JDK and JRE.

查看更多
淡お忘
6楼-- · 2020-01-24 12:50

I've met a similar problem and spent an entire day to get it fixed. Although my computer, windows7, and Rstudio are 64 bit, but my Java is 32 bit(!) Once I realized that, I download a 64 bit Java. I have to manually download, the automatic download will lead to the 32 bit version because my chrome browser is 32 bit. 64 bit Java will be automatically installed in

C:\Program Files\Java, however, 32 bit Java will be automatically installed in C:\Program Files (x86) \Java.

This is an important indicator telling me my Java is 64 bit or 32 bit.

After installing the 64 bit Java, everything works perfect!

查看更多
Root(大扎)
7楼-- · 2020-01-24 12:50

Try downloading the RStudio daily build: http://dailies.rstudio.com

It worked for me on the second try after I tried everything else (updated R, Rstudio, Java, reinstalled rJava a million times, and followed all the stackoverflow advice).

The tip came from the RStudio support forums:

RStudio is indeed failing to read some of the start-up information normally provided by R here...

We have a potential fix for this in the latest daily builds of RStudio -- if you're willing, you can try downloading and testing from http://dailies.rstudio.com

查看更多
登录 后发表回答