Matching 64 bits versions but error loading rJava - r

I have set the JAVA_HOME to JAVA_HOME="C:\Program Files\Java\jre1.8.0_251".
I have installed a 64 bits version of Java which is matching with my 64 bits R (version 4.0.2) and Windows 10 Home.
Error remains in loading rJava as below:
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/my_R_library/rJava/libs/x64/rJava.dll':
I tried to reinstalled JAVA and R, rJava cannot be loaded.
I tried the function find.java(), it runs properly
Is there any suggestion to deal with the problem?

My problem finally solved. Since my Windows is a Chinese version, it cannot recognise any Chinese characters in the paths if I installed an English version. What I have done is just installing a Chinese version R, no need to set the JAVA_HOME at all. I hope this can hope the potential use of R with their own langauge based Windows.

Once Java is installed on a Windows based PC, one must ensure it is configured in the operating system in a way that R can access it. First, check the Java Control Panel. In the windows 10 search bar, search for Configure Java, and then press from the list of choices for the Java Control Panel.
From the Control Panel main window, select the Java tab,
and then press the button.
At this point you should see at least one row of information that illustrates the version and location where you have Java installed.
If your version of Java isn't listed, you can use the > or buttons to find or add the version that had been installed but is not listed.
Exit the Java Control Panel, open a command window (type cmd in Windows search bar), and type
java -version
This should display the version of Java that is visible to Windows, as illustrated below.
Next, we need to confirm that Java is accessible within RStudio. Open RStudio and use the system() function to check the version of Java.
system("java -version")
We should receive the same result as we did with the Windows command line version of java -version.
> system("java -version")
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
[1] 0
At this point, one should be able to install rJava. However, if Java isn't accessible, we'll need to use the Sys.setenv() function to set the path for Java home.
# set JAVA_HOME to directory listed in Configure Java app, such as
# C:\Program Files\Java\jre1.8.0_231
Sys.setenv(JAVA_HOME="C:/Program Files/Java/jre1.8.0_231")
...and now we should be able to install rJava.
install.packages("rJava")
> install.packages("rJava")
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/rJava_0.9-12.zip'
Content type 'application/zip' length 1214816 bytes (1.2 MB)
downloaded 1.2 MB
package ‘rJava’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\leona\AppData\Local\Temp\RtmpWGyEQp\downloaded_packages
>

Related

error installing xlsx package with object not loaded [duplicate]

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).

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)

How to install ROracle on Windows 7 64-bit

This is a follow on to How to install ROracle package on Windows 7?
I'm getting the following error trying to build ROracle
** testing if installed package can be loaded
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'D:/Users/a101/Documents/R/win-library/3.0/ROracle/libs/x64/ROracle.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
I have RTools and 64-bit Oracle Instantclient installed
I execute the following from an Admin privieledged command line:
set OCI_LIB64=C:/Oracle/instantclient_12_1_x64
set OCI_INC=C:/Oracle/instantclient_12_1_x64/sdk/include
"C:/Program Files/R/R-3.0.0/bin/x64/R" CMD INSTALL --build ROracle_1.1-10.tar.gz
I've searched around and what I've found says this error is caused by building in mixed mode. I.e. 32-bit R with 64-bit Oracle client library or vice versa. I've been looking at this for many (many) hours and I believe I'm using all 64-bit (OS, R, Oracle client library). All the trace messages seem to indicate 64-bit everywhere. Any thoughts on what I might be missing?
To run dependency walk use Dependecy Walker, choose opening ROracle.dll in this app. I had the same issue since ROracle.dll was searching for OCI x64 (Oracle client), whereas I had x86 version of it installed on my PC.
I came across the same question, with 64bit windows and R...
Since I shifted the ROracle from 32bit to 64bit some days before. After changing the OCI_LIB64, OCI_INC and also add the 64bit instantclient dir to the env variable Path, it works fine in R and RStudio.
But I set up a task scheduler before, using Rscript.exe to run a RCode every day. That task failed since the shift with the same error:"Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared object 'E:/app/R_lib/3.4/ROracle/libs/x64/ROracle.dll': LoadLibrary failure: %1 is not a valid Win32 application."
My final solution is to restart the computer...And the task scheduler works again....guess there should be some 32bit file stored temporarily and need to be deleted before using 64bit ROracle...
You need to add the Oracle Client 32 and 64 bits witk SDK folder directory to the Windows System enviromental variables path. Also need to install rjava package (install java 64 bits) and set JAVA_HOME in R sys.setenv().
install.packages("rJava") #Install Java 64 bits
library(rJava) #Not Errors
Sys.setenv("OCI_LIB64"="C:/instantclient_12_2_64bits")
Sys.setenv("OCI_LIB32" = "C:/instantclient_12_2_64bits")
Sys.setenv("ORACLE_HOME" = "C:/instantclient_12_2_64bits")
Sys.setenv(JAVA_HOME='C:/Program Files/Java/jre1.8.0_241')
install.packages(paste0(path,"/ROracle_1.3-1.tar.gz"), repos = NULL, type = "source")
library(ROracle)
The last message in the install process should be DONE!
In the Windows System enviromental path:
C:\instantclient_12_2_64bits;
C:\instantclient_12_2_64bits\sdk;
C:\instantclient_12_2_32bits;
C:\instantclient_12_2_32bits\sdk;
hope this works!

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