Error: package ‘rJava’ could not be loaded when installing xlsx - r

Im trying to install the xlsx package. Installing works fine but when i load the library I get the following error:
> require(xlsx)
Loading required package: xlsx
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.
In addition: Warning messages:
1: package ‘xlsx’ was built under R version 3.2.3
2: package ‘rJava’ was built under R version 3.2.3
Failed with error: ‘package ‘rJava’ could not be loaded’
I googled around and say that installing the right version of Java might be the issue. However, when I downloaded the newest version and started a new r-session I still get the same issue.
Are there more people experiencing this issue? And some quick fix?

I am using Linux and when I update R or Java to use the rJava library (needed by xlsx) I need to run this commands form a shell (outside the R session)
sudo su -
R CMD javareconf
I hope this helps.

Related

How does one install rJava and qdap onto RLibrary?

I was working on an assignment that requires installing a number of packages (including rJava and qdap), and I was sucessful at that. But when I installed those projects onto RLibrary, I couldn't install Java and qdap.
I got the following errors:
> library(qdap)
Error: package or namespace load failed for 'qdap':
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(jli, FALSE)
error: unable to load shared object '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib':
dlopen(/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib, 0x000A): tried: '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
> library(rJava)
Error: package or namespace load failed for 'rJava':
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(jli, FALSE)
error: unable to load shared object '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib':
dlopen(/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib, 0x000A): tried: '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
I then tried to install Java, Java JDK, and pkgname, but got the following errors:
Warning in install.packages :
package 'Java JDK' is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Warning in install.packages :
package 'pkgname' is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
I'm not sure why I am getting these errors. I'm using RStudio Version 2022.12.0+353 (2022.12.0+353), and MacOS Monterey 12.5.

Installed rJava, Installed Java 8 update. Still cannot load rJava on MacOS Sierra

Bear in mind that I am computer illiterate and new to R. I have installed the rJava package in R studio version 1.0.143 and installed Java 8 (using MacOS Sierra). When I try to load the rJava package:
library(rJava)
I get the following error
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object
'/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so':
dlopen(/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so, 6):
Library not loaded: #rpath/libjvm.dylib
Referenced from:
/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so
Reason: image not found
In addition: Warning messages:
1: package ‘rJava’ was built under R version 3.4.2
2: running command '/usr/libexec/java_home' had status 1
Could somebody help me to interpret this error message? There is probably a very simple solution, but I am completely lost. Thank you!!
As noted in Unable to load rJava in RStudio, there is a very specific sequence of steps that must be taken to get rJava to work on a Macbook, as documented in rJava Issues #86.
Download and install Java from Oracle
Uninstall any previously installed version of rJava
Add JAVA_HOME to your .bashrc
Close & restart terminal, R and RStudio sessions so they pick up the updated JAVA_HOME
Use install.packages() to install rJava
See the URL link above for additional details on each step.

rJava Package installation failed (needed for xlsx package)

When I want to install the xlsx package, I get this error :
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
In addition: Warning message:
package ‘rJava’ was built under R version 3.3.3
Error: package ‘rJava’ could not be loaded
So I tried reinstalling rJava, but I get this :
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
In addition: Warning message:
package ‘rJava’ was built under R version 3.3.3
Error: package or namespace load failed for ‘rJava’
Do you guys have any simple solution to this ? I am not very familiar with R, and I just need it to bootstrap some data.
I had the same error recently (R Error: JAVA_HOME cannot be determined from the Registry). I found the solution here. In brief, Joachim Schork identified the problem as not the xlsx package but rather the rjava package. He explained that the problem usually is, as hartmut said, running a 64 bit version of R and a 32 bit version of Java. To resolve the problem according to his recommendation, you need to download and install the 64 bit version of Java. In my case, the solution included installing Java on my machine as it was never installed previously.

Loading R package xlsx: Error : .onLoad failed in loadNamespace()

I tried to load the R package xlsx:
library('xlsx')
But I got the following error:
Error : .onLoad failed in loadNamespace() for 'xlsx', details:
call: .jinit()
error: Cannot create Java virtual machine (-1)
In addition: Warning message:
package ‘xlsx’ was built under R version 3.2.3
Error: package or namespace load failed for ‘xlsx’
My R-session aborts when I try .jinit()
Any help is much appreciated.
Edit:
I updated R Studio to the newest version and executed
update.packages(checkBuilt = TRUE)
but still got the following error:
Error : .onLoad failed in loadNamespace() for 'xlsx', details:
call: .jinit()
error: Cannot create Java virtual machine (-1)
Error: package or namespace load failed for ‘xlsx’
Edit 2:
This question is still unsolved.
As Pascal in the comments below suggested I looked for the windows equivalent command of:
R CMD javareconf
After many hours of searching I still didn't found it.
I faced similar problem on Macbook. If you've upgraded Java recently, it is likely that you need to reconfigure.
For me, it got solved with,
step#1 sudo R CMD javareconf (On Windows, sudo not required. If you face "command not found" issue on Windows, try this)
step#2 install.packages("rJava",type='source') (inside R prompt)
Hope this helps!
In case you don't have PATH variable set up properly, try to override it by using
options(java.home="PATH TO jre")
This might fix some issues.

Error while installing R packages : Tcl/Tk support is not available on this system

I am using Linux- fedora 14 64 bit machine. While installing some of R packages , eg : DEGseq and sqldf , I am facing this error. I manually install all tcl and tk devel and core libraries using yum but the problem still persisting.
The error i am encountering while installing packages:
Warning: S3 methods ‘$.tclvar’, ‘$<-.tclvar’, ‘as.character.tclObj’, ‘as.character.tclVar’, ‘as.double.tclObj’, ‘as.integer.tclObj’, ‘as.logical.tclObj’, ‘as.raw.tclObj’, ‘print.tclObj’, ‘[[.tclArray’, ‘[[<-.tclArray’, ‘$.tclArray’, ‘$<-.tclArray’, ‘names.tclArray’, ‘names<-.tclArray’, ‘length.tclArray’, ‘length<-.tclArray’, ‘tclObj.tclVar’, ‘tclObj<-.tclVar’, ‘tclvalue.default’, ‘tclvalue.tclObj’, ‘tclvalue.tclVar’, ‘tclvalue<-.default’, ‘tclvalue<-.tclVar’, ‘close.tkProgressBar’ were declared in NAMESPACE but not found
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: fun(libname, pkgname)
error: Tcl/Tk support is not available on this system
Error : package/namespace load failed for ‘tcltk’
Error : unable to load R code in package ‘gsubfn’
ERROR: lazy loading failed for package ‘gsubfn’
* removing ‘/home/xuserL/R/x86_64-unknown-linux-gnu-library/2.15/gsubfn’
ERROR: dependency ‘gsubfn’ is not available for package ‘sqldf’
* removing ‘/home/xuser/R/x86_64-unknown-linux-gnu-library/2.15/sqldf’
I am unable to find the solution even after googling about this error.
Please tell me the set of steps i need to follow in order to sort out this problem?
Thanks in advance :)

Resources