3

I have to load an Excel file .xlsx on R, but:

library(xlsx)

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:/Users/danil/Documents/R/win-library/3.4/rJava/libs/x64/rJava.dll': LoadLibrary failure: Impossibile trovare il modulo specificato. Error: package ‘rJava’ could not be loaded

So, I tried to install Java, Java SE-Development Kit 10 and Java Runtime Environment 10, 64 bit for both. But, also in this case:

library(rJava)

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:/Users/danil/Documents/R/win-library/3.4/rJava/libs/x64/rJava.dll': LoadLibrary failure: Impossibile trovare il modulo specificato.

What can I do?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
  • Hi @francesco... welcome to SO. I've edited your title to be a bit more informative as a question. –  Apr 07 '18 at 19:07
  • No problem, i hope that it will also help anybody else. – Francesco Totti Apr 07 '18 at 19:13
  • How did you install xlsx package? Or have a look here https://stackoverflow.com/q/37735108/5784831 – Christoph Apr 07 '18 at 19:25
  • I wasnt'able to install xlsx package... It says "Error: package or namespace load failed for ‘rJava’". I don't know what to do, i'm a newbie of R. – Francesco Totti Apr 07 '18 at 20:26
  • What is your OS? Usually, when I get these errors, I look all over the error messages, such often there will be some libraries/packages suggested for installing for each operating system. – Cainã Max Couto-Silva Apr 08 '18 at 03:23
  • I use Windows 10. And no errors were found during install.packages("xlsx") and install.packages("rJava"). The problem is after, when i try to charge Java package. – Francesco Totti Apr 08 '18 at 08:55
  • I am running R version Version 1.0.143 and Java version 1.8.0_161(latest) – Francesco Totti Apr 08 '18 at 08:59
  • Sorry, i running Windows 8. And: sessionInfo() R version 3.4.4 (2018-03-15) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200) Matrix products: default locale: [1] LC_COLLATE=Italian_Italy.1252 LC_CTYPE=Italian_Italy.1252 [3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C [5] LC_TIME=Italian_Italy.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.4.4 tools_3.4.4 – Francesco Totti Apr 08 '18 at 09:10
  • Try this: https://stackoverflow.com/questions/7019912/using-the-rjava-package-on-win7-64-bit-with-r/15998358#15998358 – Somnath Bera Aug 28 '20 at 17:34

2 Answers2

2

This was happening to me as well (also Windows 10), and the problem with mine was that the environment variable was not set properly. In my case, I had to do

Sys.setenv('JAVA_HOME' = 'C:/Program Files (x86)/Java/jre1.8.0_161/')

Just change the folder name to where Java lives in your computer, and let me know if this doesn't work out.

Kim
  • 4,080
  • 2
  • 30
  • 51
  • 1
    Do you happen to know why do we need to setenv() for JAVA_HOME in R, when I had already set JAVA_HOME in system variables? Using Windows 10 – Digvijay Sawant May 14 '18 at 17:40
0

In Ubuntu 16.04 I did the following trick in RStudio:

Sys.setenv('JAVA_HOME' = '/usr/lib/jvm/java-8-oracle/jre')

Surprisingly, but

Sys.setenv('JAVA_HOME' = '/usr/lib/jvm/java-8-oracle/')

didn't work for me.

Kenelm
  • 1