error installing xlsx package with object not loaded [duplicate] - r

While loading rJava package, I receive this error:
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/ankitagarwal5/Documents/R/win-library/3.2/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
In addition: Warning message:
package ‘rJava’ was built under R version 3.2.3
Error: package or namespace load failed for ‘rJava’
I referred various posts on StackOverflow and tried to make changes accordingly, but nothing worked. These are the various steps I followed to resolve the issue:
if (Sys.getenv("JAVA_HOME")!="")
Sys.setenv(JAVA_HOME="")
library(rJava)
This didn't work.
Then I tried this:
options(java.home="C:\\Program Files\\Java\\jre1.8.0_91\\")
library(rJava)
This didn't work either.
My jvm.dll is at this location in my Windows 7 64 bit OS - C:\Program Files (x86)\Java\jre1.8.0_91\bin\client
I also added C:\Program Files (x86)\Java\jre1.8.0_91\bin\client to my PATH variable in my Environment variables and restarted RStudio and tried to install and load rJava again. That also didn't work.
I would really appreciate if someone could please help me resolve this issue.
Thanks guys!

This worked for me -
This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using.
Note that it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version .
You can pick the exact version of Java you wish to install from this link. If you might (for some reason) work on both versions of R, you can install both version of Java (Installing the “Java Runtime Environment” is probably good enough for your needs).
(Source: Uwe Ligges)
Other possible solutions is trying to re-install rJava.
If that doesn’t work, you could also 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)
Refer this link - http://www.r-bloggers.com/how-to-load-the-rjava-package-after-the-error-java_home-cannot-be-determined-from-the-registry/

I encountered the same problem. Be sure to check the file path for Java. To solve the error I needed to download 64bit Java version. However the following code in R did not work as the folder was incorrect for the latest version for Java:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre7') # for 64-bit version
Instead I changed the name to:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_144')
Hope that helps

I have noticed in different fresh installations of R, RStudio and rJava in WIndows, that what fixes the error is:
Uninstall R
Reinstall R but only selecting one architecture. Example, x64, or x86, but not both. That tends to confuse R or RStudio when they are compiling.
In my case, I fixed the message
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/ankitagarwal5/Documents/R/win-library/3.2/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Following steps 1 and 2 above.

I tried what the other have said to not avail. For me the solution was to eliminate the old folders and shortcuts of R version 32 bit on my computer that remained there even after uninstalling.

This happened to me when Java was updated to a 32-bit, but R required a 64-bit version.
The solution:
Simply download the 64-bit version of Java
install it.
Restart RStudio
Everything should work
Where to download 64-bit java:

I guess your OS architecture and R architecture are not matching. If they are matching, the following might be the problem
It worked for me after i added the R library path to the environment variables list on my windows 7.
So,
Add 'C:/Users/Rohan-PC/Documents/R/win-library/3.1' this path to the Path variables list under System variables list(not to be confused with the PATH variable under User variables). Restart R and try loading the library. It works!!!!!

If you have both 64-bit R and 32-bit R versions installed, try from each one.
For me it worked on R 64bits but not R 32bits.
But of course that depends on your java version (64-bit Java vs 32-bit Java).

Related

R - Error : .onLoad failed in loadNamespace() for 'rJava'

While loading rJava package, I receive this error:
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/ankitagarwal5/Documents/R/win-library/3.2/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
In addition: Warning message:
package ‘rJava’ was built under R version 3.2.3
Error: package or namespace load failed for ‘rJava’
I referred various posts on StackOverflow and tried to make changes accordingly, but nothing worked. These are the various steps I followed to resolve the issue:
if (Sys.getenv("JAVA_HOME")!="")
Sys.setenv(JAVA_HOME="")
library(rJava)
This didn't work.
Then I tried this:
options(java.home="C:\\Program Files\\Java\\jre1.8.0_91\\")
library(rJava)
This didn't work either.
My jvm.dll is at this location in my Windows 7 64 bit OS - C:\Program Files (x86)\Java\jre1.8.0_91\bin\client
I also added C:\Program Files (x86)\Java\jre1.8.0_91\bin\client to my PATH variable in my Environment variables and restarted RStudio and tried to install and load rJava again. That also didn't work.
I would really appreciate if someone could please help me resolve this issue.
Thanks guys!
This worked for me -
This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using.
Note that it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version .
You can pick the exact version of Java you wish to install from this link. If you might (for some reason) work on both versions of R, you can install both version of Java (Installing the “Java Runtime Environment” is probably good enough for your needs).
(Source: Uwe Ligges)
Other possible solutions is trying to re-install rJava.
If that doesn’t work, you could also 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)
Refer this link - http://www.r-bloggers.com/how-to-load-the-rjava-package-after-the-error-java_home-cannot-be-determined-from-the-registry/
I encountered the same problem. Be sure to check the file path for Java. To solve the error I needed to download 64bit Java version. However the following code in R did not work as the folder was incorrect for the latest version for Java:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre7') # for 64-bit version
Instead I changed the name to:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_144')
Hope that helps
I have noticed in different fresh installations of R, RStudio and rJava in WIndows, that what fixes the error is:
Uninstall R
Reinstall R but only selecting one architecture. Example, x64, or x86, but not both. That tends to confuse R or RStudio when they are compiling.
In my case, I fixed the message
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/ankitagarwal5/Documents/R/win-library/3.2/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Following steps 1 and 2 above.
I tried what the other have said to not avail. For me the solution was to eliminate the old folders and shortcuts of R version 32 bit on my computer that remained there even after uninstalling.
This happened to me when Java was updated to a 32-bit, but R required a 64-bit version.
The solution:
Simply download the 64-bit version of Java
install it.
Restart RStudio
Everything should work
Where to download 64-bit java:
I guess your OS architecture and R architecture are not matching. If they are matching, the following might be the problem
It worked for me after i added the R library path to the environment variables list on my windows 7.
So,
Add 'C:/Users/Rohan-PC/Documents/R/win-library/3.1' this path to the Path variables list under System variables list(not to be confused with the PATH variable under User variables). Restart R and try loading the library. It works!!!!!
If you have both 64-bit R and 32-bit R versions installed, try from each one.
For me it worked on R 64bits but not R 32bits.
But of course that depends on your java version (64-bit Java vs 32-bit Java).

Unable to load rJava on R

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:
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.
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.
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.
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!
Faced similar error message.
Tried a few steps listed here.
Set Env. Variable, JAVA_HOME. => Didn't work.
Tried to install rJava +> Didn't work
Steps 3,4,5 worked..
Updated my Java 64 bit version 8.xx (latest available)
install.packages(rJava) ==> Success
install.packages(RWeka) ==> Success
I get this error every time Java sneaks an update onto my PC. When I go:
Sys.getenv("Path")
I find something in the output which looks like
C:\\Program Files \\Java\\jre1.8.0_112\\bin\\server\\
where the last few digits of the jre subfolder are outdated.
To fix this everywhere, you might want to edit the Windows environment variable. Do this by going WINDOWS + X key, selecting Command Prompt (Admin) from the menu, and typing
rundll32.exe sysdm.cpl,EditEnvironmentVariables
in the command box. This will call up this dialog box with edit rights for the PATH variable (and other system variables):
The Windows interface for editing long environment variables is a bit unwieldy, so after I click Edit... I like to copy-paste the resulting mess of paths to Notepad.exe, do the work there, and copy-paste back.
Had the same issue:
I was running 64-bit R you can check which version by closing and re-openning RStudio. It should be at the top.
I had 32-bit java installed i.e. Java folder was within C:\Program Files (x86).
I simply went on to Java.com and downloaded the 64-bit Java and added it's location at the end of the PATH in System variables and I can load rJava now. (The installation asked me to get rid of the old version which I did)
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.
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
I tried the above alternatives but it didnt work for me.
I found the solution here. Simply setting the JAVA_HOME allowed the rJava library to be loading fine.
Sys.getenv("JAVA_HOME")
Sys.setenv(JAVA_HOME="")
library(rJava)

Problems when trying to load a package in R due to rJava

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?
The reason is probably linked to the fact you are using a 64-bit OS and R version but do not have Java installed with the same architecture.
What you have to do is to download Java 64-bit from this page: https://www.java.com/en/download/manual.jsp
After that just try to reload the xlsx package. You shouldn't need to re-start R or if it does not work restart once.
Its because either one of the Java versions(32 bit/64 bit) is missing from your computer. Try installing both the Jdks and run the code.
After installing the Jdks open R and type the code
system("java -version")
This will give you the version of Jdk installed. Then try loading the rJava package. This worked for me.
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.
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.
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.
An alternative package that you can use is readxl. This package doesn't require external dependencies.
For reading/writing excel files, you can use :
readxl package for reading and writexl package for writing
openxlsx package for reading and writing
With xlsx and XLConnect (which use rjava) you will face memory errors if you have large files
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.
If you have this issue with macOS, there is no easy way here: ( Especially, when you want to use R3.4. I have been there already.
R 3.4, rJava, macOS and even more mess
For R3.3 it's a little bit easier (R3.3 was compiled using different compiler).
R, Java, rJava and macOS adventures
For me, I simply needed to make sure the Java was 64-bit (to match R).
Here's how I downloaded and installed 64-bit Java:
Go to: https://www.java.com/en/download/manual.jsp
Click on "Windows Offline (64-bit)"
Install it (you may need to find the file that downloaded and double click it, or it may automatically install)
Close and reopen your R/RStudio session
Everything will work as expected!

JavaGD fails to load

Could someone please help.
I had Deducer working with R 2.14 but now that I have updated to 2.15.1 I can't get JGR to load. I have loaded JGR and Deducer.
This is the message I get when installing
Loading required package: JavaGD
Error : .onLoad failed in loadNamespace() for 'JavaGD', details:
call: .Call("RegGetStrValue", c(key, "CurrentVersion"), PACKAGE = "JavaGD")
error: C symbol name "RegGetStrValue" not in DLL for package "JavaGD"
Error: package ‘JavaGD’ could not be loaded
I have removed all old versions of R and Ver 2.15.1 - reinstalled R and still get this message.
Is it possible that this is a Registry problem and if so where should I look.
I have searched and although there seem to be simiar reported issues, none are exactly the same from the ones that I have seen. I certainly dont seem to have m,ultiple versions of JavaGD in my library and the Namesake file is in the folder JavaGD.
I am running Win 7 32 bit ver on fairly current Dell Laptop.
R seems to work fine and I am using R-Studio most of the time and that works fine as well.
Any help would be appreciated
7 years on form the OP's original issue choosing the right Java Download is critical for 64-bit machines which most of our RStudio environments are synced to work with. For whatever reason, downloading the 64-bit JRE is difficult. To avoid the same error presented by Deducer more recently be sure to download the 64-bit Java JRE from https://www.java.com/en/download/manual.jsp. Note, the 64-bit version must be downloaded offline as instructed (usually bottom of Windows downloads). Check that the installation path is c:\Program Files\Java and not c:\Program Files(x86)\Java. That plus the JDK should fix this problem going forward.

How can I install rJava for use with 64bit R on a 64 bit Windows computer?

I installed iplots and rjava packages. When I do this library(iplots), I get the following error. I do have JDK installed on my pc.
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
Error: package ‘rJava’ could not be loaded
The error is telling you that there is no entry in your Registry that tells R where Java is located on your machine. Either your registry is corrupt, but more likely you haven't installed Java. You can install either the Java Runtime Environment or the Java Development Kit.
(You can download Java here.)
If you installed Java, try reinstalling it. This should put the entries back in your Registry.
If that doesn't work, you can start looking at exactly where R is looking for your Registry entries. The function that rJava uses to find Java is in the rJava:::.onLoad function. Within that function there is a subfunction called find.java. I copy the contents here:
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
}
Copy and paste this into your R window, and then run it find.java(). rJava is looking for an entry for JavaHome. If that isn't listed, then it is missing from your registry.
You could also manually set the directory of your Java location by setting it before loading the library:
Sys.setenv(JAVA_HOME='C:\\Your\\Java\\Directory')
library(rJava)
If like me you do not have admin rights to install 64-bit Java, just open 32-bit R and it should work ok on your 64 bit PC as part of the problem seems to be the rJava library function calls embedded Java functions/routines, which may only have being designed for 32-bit interface with Excel/Windows and possibly too large a task at the time to change everything.
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.
Any Linux users here, run command:
sudo R CMD javareconf
That typically needs to be run after an update of the system Java installation,
as suggested here

Resources