Problems when trying to load a package in R due to

2019-01-16 22:07发布

When I type require(xlsx) in order to load the package xlsx in R, the following messages is shown:

> require(xlsx)
Loading required package: xlsx
Loading required package: xlsxjars
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
Failed with error:  ‘package ‘rJava’ could not be loaded’

I've also tried to load the rJava package manually but got this error message:

require(rJava)
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: fun(libname, pkgname)
  error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.

Do you have any suggestion on how to solve the problem?

标签: r rjava r-xlsx
9条回答
The star\"
2楼-- · 2019-01-16 22:46

Answer in link resolved my issue.

Before resolution, I tried by adding JAVA_HOME to windows environments. It resolved this error but created another issue. The solution in above link resolves this issue without creating additional issues.

查看更多
祖国的老花朵
3楼-- · 2019-01-16 22:51

I had a similar issue. It is caused due the dependent package 'rJava'. This problem can be overcome by re-directing the R to use a different JAVA_HOME.

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

This worked for me.

查看更多
Fickle 薄情
4楼-- · 2019-01-16 22:52

If you have this error in RStudio, use Lauren's environmental code above and change your R version to the 32 bit version in Tools, Global Options. There should be both 32bit and 64bit R options if you have a newer version. This will require a restart of R, and limit your memory options. Installing the 64 bit version of the jre won't be required though.

查看更多
霸刀☆藐视天下
5楼-- · 2019-01-16 22:54

An alternative package that you can use is readxl. This package don't require external dependencies.

查看更多
聊天终结者
6楼-- · 2019-01-16 22:57

I had a similar problem what worked for me was to set JAVA_HOME. I tired it first in R:

Sys.setenv(JAVA_HOME = "C:/Program Files/Java/jdk1.8.0_101/")

And when it actually worked I set it in System Properties -> Advanced -> Environment Variables by adding a new System variable. I then restarted R/RStudio and everything worked.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-01-16 22:59

I think I found the resolution as I had the same problem!

My fix was to install both 32 bit and 64 bit JRE (Java Runtime Environment) version 8 update 181.(I require 32 bit for another application, but your fix can well be just re-installing 64 bit on its own.)

查看更多
登录 后发表回答