package 'rJava' could not be loaded

Maïna Kerbrat picture Maïna Kerbrat · Apr 4, 2016 · Viewed 13.2k times · Source

I cannot solve my problem with rjava on R.

When I install rJava package and require it, I have no issues .

install.packages("devtools")
install.packages("rJava")
library(rJava)
Sys.setenv(JAVA_HOME="C:/Program Files (x86)/Java/jre1.8.0_77")

devtools::install_github("kassambara/r2excel",INSTALL_opts="--no-multiarch")

When I compile the last line, I have this issue:

* installing *source* package 'r2excel' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: impossible de charger l'objet partagé 'C:/Users/itm/Documents/R/win-library/3.2/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  %1 n’est pas une application Win32 valide.

Error : package 'rJava' could not be loaded
Erreur : le chargement a échoué
Exécution arrêtée
ERROR: loading failed for 'x64'
* removing 'C:/Users/itm/Documents/R/win-library/3.2/r2excel'

And I try using 32 bit R. but no change !

An other package called 'xlsx' needs rJava to run and I can use it.. I don't understand why..

  R.version
               _                           
platform       i386-w64-mingw32            
arch           i386                        
os             mingw32                     
system         i386, mingw32               
status                                     
major          3                           
minor          2.3                         
year           2015                        
month          12                          
day            10                          
svn rev        69752                       
language       R                           
version.string R version 3.2.3 (2015-12-10)
nickname       Wooden Christmas-Tree 

Thanks for you help

Answer

iauhs picture iauhs · Apr 8, 2016

Because the JDK you are using is 32 bit, reinstall the 64 bit from the Oracle Website

And then do :

Sys.setenv(JAVA_HOME="C:\\\PATH\\\TO\\\JAVA\\\")
library(rJava)