15

So I have tried the previously proposed answer to my question. but I am still having the same error message: I am trying to load the rJava library in R

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:/Users/Lauriane/Documents/R/win-library/3.3/rJava/libs/x64/rJava.dll':   
LoadLibrary failure:  The specified module could not be found.  
Error: package or namespace load failed for ‘rJava’

Please help,

Thanks

d.b
  • 32,245
  • 6
  • 36
  • 77
flawa
  • 151
  • 1
  • 1
  • 4
  • may be this can help you, http://stackoverflow.com/questions/27661325/unable-to-load-rjava-on-r – Aditi Apr 18 '17 at 12:21
  • You can check whether your Java architecture is is same as that of the R version you are using. `rJava` needs both of them to be on the same architecture. 32-bit or 64-bit. I had the same problem. – samkart Jul 13 '17 at 12:49
  • This may help. It helped for me. https://stackoverflow.com/a/30073113/5238639 – prashanth Nov 20 '17 at 07:02
  • Here's what worked in my case: https://stackoverflow.com/a/70417282/5783745 – stevec Dec 20 '21 at 23:41

5 Answers5

8

For me the problem was caused because a 32-bit Java version was installed on the system, but I was running 64-bit version of R. Installing the 64-bit Java version solved the problem with rJava namespace environment. Because I am running a 32-bit browser I had to manually download the 64-bit Java version.

tomka
  • 2,516
  • 7
  • 31
  • 45
  • This worked for me. https://www.java.com/fr/download/manual.jsp then in R Sys.setenv(JAVA_HOME="C:/Program Files/Java/jre1.8.0_251/") ; library(rJava) – Gildas May 20 '20 at 12:22
5

What worked for me is explained here. Essentially, do sudo R CMD javareconf in the terminal and reboot.

Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
2

I had the same problem and, as suggested in previous comments, I manually installed the 64-bit version, selecting it here. I only had to restart R. It worked perfectly.

Tezcatlipoca
  • 51
  • 1
  • 1
  • 5
2

I'll just add one more possible solution, since I tried all of the suggestions listed above (reinstalling Java x64, installing both JDK & JRE, setting JAVA_HOME, sudo R CMD javareconf or even sudo R CMD javareconf -n seen elsewhere, and more) but none of them worked and I kept getting the following error:

> library(rJava)
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.6/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.6/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.6/Resources/library/rJava/libs/rJava.so
  Reason: image not found

There were 2 possible solutions that helped me get through this error:

  • Go to the location of your Java installation (in my Mac OS it was /Library/Java/JavaVirtualMachines/) where you'll find a folder titled something like "jdk-13.0.1.jdk" (depending on your JDK version). Changing its name to "jdk-11.0.1.jdk" (or whatever is mentioned in your error) should solve your problem.

But maybe even better is to do the following instead:

  • Go to the file referenced in the error: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, open it in a text editor (such as TextEdit) and change "jdk-11.0.1.jdk" to "jdk-13.0.1.jdk" (or whatever is the folder referenced in your error and what is actually in your Java folder, respectively).

Either way worked for me but the latter looks a bit cleaner to me. Hope this helps someone!

Brunox13
  • 775
  • 1
  • 7
  • 21
0

I had the same problem.

From what I've understood this was due to two reasons: a) R being 64-bits and Java being on 32-bits, b) R being installed in D:\Documents and Java being installed in C:\Programmes.

I've solved the issue by:

  • Disinstalling all previous versions of Java
  • Disinstalling both R and RStudio
  • Installing both R, Rstudio and Java in 64 bits in a new folder called D:\Programmes
  • For Java I have installed both the JDK and JRE in the same folder
  • Setting JAVA_HOME as an environment variable making sure that the environment variable was pointing to bin.