-2

I am running Win 10 64-bi with Java version 1.8.0.221. when loading xlsx package I am getting an error in R Studio with version 3.5.2 - also 64-bit. The error is in loading rJava. any thoughts on how can I fix this? I am stuck and can't move forward. Thanks.

trying URL 'https://mran.microsoft.com/snapshot/2019-02-01/bin/windows/contrib/3.5/xlsx_0.6.1.zip'
Content type 'application/zip' length 458979 bytes (448 KB)
downloaded 448 KB

package ‘xlsxjars’ successfully unpacked and MD5 sums checked
package ‘xlsx’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\<user>\AppData\Local\Temp\RtmpIZaYPe\downloaded_packages
> library(xlsx)
Error: package or namespace load failed for ‘xlsx’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/<user>/Documents/R/win-library/3.5/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  The specified module could not be found.
r2evans
  • 141,215
  • 6
  • 77
  • 149
user3150378
  • 335
  • 1
  • 5
  • 14

1 Answers1

1

I added the following and then rJava loaded without error.

Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_221')
user3150378
  • 335
  • 1
  • 5
  • 14
  • 3
    Perhaps you should revise or delete [your comment](https://stackoverflow.com/questions/58347446/onload-failed-in-loadnamespace-for-rjava?noredirect=1#comment103050555_58347446) where you said *"Most questions are older and hence may not be relevant"*, since your answer here is **exactly** (version/release number notwithstanding) what is in the other question. – r2evans Oct 11 '19 at 20:03
  • This will only work for the current session. Maybe edit Rprofile?! – NelsonGon Oct 12 '19 at 00:28
  • Yes, I added this to .RProfile. As for older versions, I was not sure if there was a change due to package and R version changes and wanted to make sure to find the latest info. – user3150378 Oct 14 '19 at 20:03