Cannot install library(xlsx) in R and look for an alternative - r

I use R version 3.0.3. I was not able to install library(xlsx). Error message:
Loading required package: 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.0.3/library/rJava/libs/x64/rJava.dll':
LoadLibrary failure: The specified module could not be found.
I then tried to install rjava on its own. Got the error message below:
library("rJava", lib.loc="C:/Program Files/R/R-3.0.3/library")
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.0.3/library/rJava/libs/x64/rJava.dll':
LoadLibrary failure: The specified module could not be found.
Is there another way to load excel file in R?

Here are some possible solutions:
Install 64-bit version of Java. Here is the download link of Java.
Re-install rJava.
Manually set the directory of your Java location by setting it before loading the library
Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jre7") # for 64-bit version
Sys.setenv(JAVA_HOME="C:\\Program Files (x86)\\Java\\jre7") # for 32-bit version
library(rJava)
Source: here

This problem is generally caused by x86 vs x64 bit differences between the R session and the install Java edition. By default Java installs the x86 version and you have to search for the x64 version. if you look at the version of Java you have installed and then open your R session to the same if your using R studio you can click on Tools.GlobalOptions and then select the version you need. ;-)

For mac user, installing Java for OS X 2014-001 works for me
https://support.apple.com/kb/DL1572?locale=en_US

For Windows 10 Pro users 64 bit OS, use
Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jre1.8.0_144")

install.packages("openxlsx") try to install OPENXLSX instead of XLSX package. Now, the required library will work properly. library(openxlsx)

For MAC OS X follow these steps in order:
Use this command in the Terminal: sudo R CMD javareconf
Restart BaseR and RStudio...
in RStudio console: install.packages("xlConnect")
in RStudio console: library(xlConnect)
in RStudio console: library(xlsx)
Problem solved!

Related

Package ("qdap") fails to load with multiple errors

While installing qdap I have not faced any errors. But when loading the library, I face the follwing errors.
> library(qdap)
Loading required package: qdapDictionaries
Loading required package: qdapRegex
Loading required package: qdapTools
Loading required package: RColorBrewer
Error: package or namespace load failed for ‘qdap’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
I read in another question that we need to install the JAVA 64bit (as my Win 10 is 64-bit) and load the JAVA home. So I downloaded the 64-bit java file and also set the JAVA_HOME to the directory.
> Sys.setenv(JAVA_HOME='C:/Program Files (x86)/Java/jre1.8.0_231')
> library(qdap)
Error: package or namespace load failed for ‘qdap’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/Admin/Documents/R/win-library/3.6/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
I have uninstalled and installed the latest R software (3.6.2; I've checked both 32-bit and 64-bit options), restarted R-studio as well, to no avail.
The issue is fixed. Although I'm not 100% sure what solved, here is what i have done.
The error %1 is not a valid Win32 application. is indicating 32-bit.
So I started Rgui console (32-bit) (opened from the directory C:\Program Files\R\R-3.6.2\bin\i386 ). The library(rJava) command works well and so does library(qdap).
Then I changed the options in Rstudio to choose 32-bit R [Tools -> Options -> General]. But setting this will impact high memory consuming executions. After a while (when I started facing memory issues), I switched the RStudio to use the 64-bit R.
The error did not appear after that and I was able to load the 'qdap' library.

xlsx package can't be loaded

XLSX package is not loading in WIndows 7 with Rstudio 3.5.3
Error: package or namespace load failed for ‘xlsx’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
This error is likely resolved by installing a Java version (e.g. 64-bit Java or 32-bit Java) that corresponds to the type of R version that you are using (e.g. 64-bit R or 32-bit R).
# check which version of R you are running
Sys.getenv("R_ARCH")
# check which version of Java is being utilized by R
system("java -version")
If you need a different version of Java then you'll need to manually download and install the right version from here. Don't forget to restart R and your browser after you install Java.

rJava installation fails on macOS 10.14

After upgrading to MacOS Mojave (10.14.1), I'm no longer able to install rJava for R version 3.5.1 with Java version "1.8.0_102" installed.
I tried the previous solution for MacOS 10.11 but it still did not work, giving this error:
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 '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
Reason: image not found
Posting the solution I found in case it helps others -- I don't quite understand why this work or if it's the right way so looking for better alternatives!
This issue lead to this Apple forum where it's stated
For legacy software that looks for the macOS headers in the base system under /usr/include, please install the package file located at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg
To do this, open terminal and run these commands
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
then follow prompts to install the package.
After this, in the terminal, configure rJava and install as in the previous answer
sudo R CMD javareconf
R -e "install.packages('rJava')"
and it should install without problem.
After installing JDK 11.04 LTS I rain into the same error in R Studio on Mojave
R was expecting Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
Despite running sudo R CMD javareconf the error still persisted
Therefore I browsed to /Library/Java/JavaVirtualMachines/ in finder and renamed the folder "jdk-11.0.4.jdk" to "jdk-11.0.1.jdk"
Restarted R and both library(rJava) and library(xlsx) now work.
Hope this helps someone
I ran into the exact problem. I solved it by:
Install the latest version of Java (dmg file)
Install rJava in Studio: install.packages("rJava")
In the terminal: sudo mv jdk-12.0.1.jdk jdk-11.0.1.jdk
Otherwise the following error will appear in Rstudio:
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 '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
Reason: image not found
In Rstudio: library(rJava)
rJava should have been loaded without issues.
I ran into same issue, when i was trying to install "rJava" in my macOs (Mojave version).
Below steps i executed to resolve issue.
R version : 3.6.1
issue : configure: error: one or more Java tools are missing.
*** JDK is incomplete! Please make sure you have a complete JDK. JRE is not sufficient.
solution : execute below command in your terminal
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_162, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk(your Java version)/Contents/Home
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
$ export PATH=$JAVA_HOME/bin:$PATH
$ R CMD javareconf
$ R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")'

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.

error in installing RWeka package in R

After getting RWeka package is sucessfully unpacked, when command library("RWeka") is executed it is showing an error:
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 message:
package ‘RWeka’ was built under R version 3.2.3 Error: package or
namespace load failed for ‘RWeka’
As the error states, make sure you have Java installed of the same architecture as R. For example if you have 32-bit R, you need to have 32-bit Java installed.
If your system is 32 bit, get yourself a 32-Bit java. If the system is 64-Bit go for 64bit java. I faced the same issue as my system is 64-Bit and i accidentally installed 32-Bit java. Uninstalled and reinstalled a 64-bit. Sorted now.

Resources