.onLoad failed in loadNamespace() for 'rJava' when installing a package .onLoad failed in loadNamespace() for 'rJava' when installing a package r r

.onLoad failed in loadNamespace() for 'rJava' when installing a package


The Java environment variable is empty

> Sys.getenv('JAVA')[1] ""

Based on a suggestion, I tried setting the JAVA environment variable to point to the 64 Bit version of Java (because I am running R 64 bit, as you could see from the sessionInfo, but that doesn't work:

> Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_45')> install()Installing javaOnloadFailed"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save  \  --no-restore CMD INSTALL  \  "C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed"  \  --library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source  \  --install-tests * installing *source* package 'javaOnloadFailed' ...** R** preparing package for lazy loading** help*** installing help indices** building package indices** testing if installed package can be loaded*** arch - i386Error : .onLoad failed in loadNamespace() for 'rJava', details:  call: inDL(x, as.logical(local), as.logical(now), ...)  error: unable to load shared object 'C:/Users/adb2018/Documents/R/win-library/3.2/rJava/libs/i386/rJava.dll':  LoadLibrary failure:  %1 is not a valid Win32 application.Error: loading failedExecution halted*** arch - x64ERROR: loading failed for 'i386'* removing 'C:/Users/adb2018/Documents/R/win-library/3.2/javaOnloadFailed'Error: Command failed (1)

I then tried to set the JAVA environment variable such that it points to the 32 bit version of Java on my system, and then it works!

> Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre1.8.0_45\\')> install()Installing javaOnloadFailed"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save  \  --no-restore CMD INSTALL  \  "C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed"  \  --library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source  \  --install-tests * installing *source* package 'javaOnloadFailed' ...** R** preparing package for lazy loading** help*** installing help indices** building package indices** testing if installed package can be loaded*** arch - i386*** arch - x64* DONE (javaOnloadFailed)[INFO] Updating the R environment index started...[INFO] The R environment index was updated successfully.

I don't quite understand why I need to point to Java 32 bit to make R 64 bit work, but that's what seems to be the case.

By the way, don't stumble over my package name "javaOnLoadFailed". I just created a minimal package with that name to test the problem.


Many packages fail install because they are not meant to run on i386 platform but the standard installation process tries to do that. Users waste a lot of time with jvm.dll and PATH and JAVA_HOME when the real fix is to force the installed to just forget about i386. Use option for install.packages. (this also works when drat library is used. (credit goes to Dason)

install.packages("SqlRender",INSTALL_opts="--no-multiarch")


I have found the same problem when trying to install a package only available in Github.
This solved for me:

devtools::install_github("snowflakedb/dplyr-snowflakedb", INSTALL_opts=c("--no-multiarch"))