rJava loading error- "character vector expected" - r

I am using 64 bit windows 7 & 64 bit R 3.2.0. I have downloaded rJava package, but it is giving an error as follows.
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dirname(this$RuntimeLib) error: a character vector argument
expected In addition: Warning message: package ‘rJava’ was built under
R version 3.2.2 Error: package or namespace load failed for ‘rJava’
I searched stackoverflow for answers, and did the following:
1) Added the jvm.dll file to my PATH variable, i.e. in the following directory:
C:\Program Files\Java\jdk1.8.0_25\jre\bin\
2) I am using 64 bit R 3.2.0 & checked if the JVM version was 64 bit or not, typing the following on the command line:
java -d64 -version
It gave the following output:
C:\Users\xyz> java -d64 -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
So at least the JVM matches with R.
So what more needs to be done to make rJava work? I also checked my PATH variable and it seems okay.

I know this is way too late, but did you try switching R versions as a diagnostic step?
For RStudio 1.0.136: Tools -> Global Options... -> General: R version: Change - Choose 32 bit.
Changing versions worked for me and prompted me to revisit my java installation. (Ended up just using R32)
Got the same error with R64:
Loading required package: XLConnectJars
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dirname(this$RuntimeLib)
error: a character vector argument expected
Error: package ‘XLConnectJars’ could not be loaded
Was running RStudio on Windows 10 using machine's default R64.

Ya must specify where the jdk is. For example:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jdk1.8.0_161')
then it should work.

Related

I can't install the zenplots package in R?

I am having difficulty installing the zenplots package in R. For some odd reason when I use install.packages('zenplots') on my machine (Mac OS Catalina V-10.15.7) it installs fine... but when I try and install it on my second machine (also Mac OS Catalina V-10.15.7) and if I try and install it on my institutes server I get the following error:
Warning in fun(libname, pkgname) : couldn't connect to display ":0"
Error : package or namespace load failed for ‘loon’: .onLoad failed
in loadNamespace() for 'loon', details: call:
structure(.External(.C_dotTcl, ...), class = "tclObj") error: [tcl]
couldn't connect to display ":0".
Error: unable to load R code in package ‘zenplots’ Execution halted
I have also tried to install directly from GitHub using remotes::install_github('great-northern-diver/zenplots', force = T) but I get the same error as above.
I have even tried using install.packages("zenplots", repos="http://R-Forge.R-project.org") which works but unfortunatley this version doesn't contain all the functions found in zenplots.
My R version is above version 3.4.0, which is required for zenplots and as per the documentation I have already installed the graph package from BioConductor.
Any suggestions as to what might be the issue here?
I would guess that the R on your server was compiled without some feature required by the library. My guess: it is missing either tcltk or X11 support. To check do the following:
capabilities()
And see which features return FALSE, meaning they are not enabled.

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

R: rJava package fails to load

I've installed the rJava pack successfully. However, when I run the command library(rJava), I get the following error.
> library(rJava) Error : .onLoad failed in loadNamespace() for 'rJava', details: call: fun(libname, pkgname) error: JAVA_HOME
cannot be determined from the Registry Error: package or namespace
load failed for ‘rJava’
How can I solve this issue?
I had this problem running XLConnect as well. It turned out that my instance of R was unable to see the Jave Virtual Machine on my 64 bit Windows computer at work. I simply found the 64 bit version of my jvm.dll file in the folder where it lives.
You can just at the path to that .dll file to your library or require() function and it should undo the madness, although, in my case, I had to update Java completely because it was too old and set this at the beginning of my script to point to the JAVA home.
Sys.setenv(JAVA_HOME="yourpathhere")
See if that works.

Problems requiring rJava in Windows

I am using a 64-bit machine, with the latest version of R (3.1.2), the latest RStudio version (0.98.1091) and the latest JAVA (Version 8 Update 31).
I tried to require rJava (rJava_0.9-6) and the result is the following error:
require(xlsx)
Carregando pacotes exigidos: rJava
Error : .onLoad falhou em loadNamespace() para 'rJava', detalhes:
chamada: fun(libname, pkgname)
erro: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
Failed with error: ‘package ‘rJava’ could not be loaded’
I already tried to re-install Java with no sucess.
Does anybody know how can I solve this problem?
I think the problem on this occasion is that your Java is 32-bit, whereas your R is 64-bit. This is why you get a R and Java have different architectures error.
In order to check what your Java version is on Windows type:
java -d64 -version
on the command line as it is mentioned here.
I think that once you install the correct Java version i.e. the 64-bit on this occasion then loading your xlsx library will work!
The architecture of Java you get for install from the regular Java download web page depends on the architecture of browser you’re using (32-bit or 64-bit) when you download it. This happens without any fanfare. Try the Java manual download page, select the 64-bit version of Java for your OS, install it, and then (after restarting R) try your R packages again.

Error rJava 64bit R&Eclipse

I have been trying to switch to 64-bit environment but i get stuck with rJava not working.
I have followed thread where people where having the same problem and their solution (JDK, JVM.DLL, environment variables etc..) but i am still stuck
Here is the error i get:
Loading required package: Rbbg
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 'H:/R/R-2.15.2/library/rJava/libs/x64/rJava.dll':
LoadLibrary failure: The specified path is invalid.
Failed with error: 'package 'rJava' could not be loaded'
Here is R.version
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 2
minor 15.2
year 2012
month 10
day 26
svn rev 61015
language R
version.string R version 2.15.2 (2012-10-26)
Thanks in advance
The problem because R can't find the jvm for the 64 architecture.
Normally if you have installed it you will get something like
C:\Program Files\Java\jre7\bin\server
Add this to your windows path and restart R.
Edit To ckeck if all things are right:
Type:
Sys.getenv()['PATH']
you get the environment variables inclusing the path for jvm.dll. If youd'ont have the jvm path here you need to add it using the usual Advanced System Settings method and restart your R console so this take effect.
Sys.getenv()['ProgramW6432']
You get C:\Program Files for the 64 archtitecture.

Resources