Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Getting R, Java, and RWeka to play nice
# R, Java, and RWeka errors
**TL;DR version**
On macOS
1. Make sure up-to-date Java JDK is installed
2. Reconfigure R's java paths: R CMD javareconf
3. Install rJava from source: install.packages("rJava", type = 'source')
4. Install RWeka: install.packages("RWeka")
On Linux
1. Install/Update open JDK 8 from system repositories
2. Install r-cran-rjava from system repositories
3. Reconfigure R's java paths: R CMD javareconf
4. Install RWeka.
**Long version**
A colleague ran into issues installing the R package RWeka on OSX. Here is the original code and output:
```{r, eval=F}
> install.packages("RWeka")
Installing package into/Users/[redacted]/Library/R/3.3/library
(aslibis unspecified)
There is a binary version available but the source version is later:
binary source needs_compilation
RWeka 0.4-26 0.4-31 FALSE
installing the source packageRWeka
trying URL ''
Content type 'application/x-gzip' length 409473 bytes (399 KB)
downloaded 399 KB
* installing *source* packageRWeka...
** packageRWekasuccessfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'RWeka', details:
call: .jnew("weka/core/WekaPackageClassLoaderManager")
error: java.lang.UnsupportedClassVersionError: weka/core/WekaPackageClassLoaderManager : Unsupported major.minor version 51.0
Error: loading failed
Execution halted
ERROR: loading failed
* removing/Users/[redacted]/Library/R/3.3/library/RWeka
Warning in install.packages :
installation of packageRWekahad non-zero exit status
The downloaded source packages are in
I have not been able to reproduce this exact error, but installing RWeka on both my Linux desktop (Mint 18) and my laptop (macOS 10.12.3) produced other errors.
On MacOS, my error was:
install.packages("rJava") # Success!
install.packages("RWeka") # FAILED:
# JavaVM: requested Java version ((null)) not available. Using Java at "" instead.
# JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib
# JavaVM FATAL: Failed to load the jvm library.
# Error : .onLoad failed in loadNamespace() for 'RWekajars', details:
# call: .jinit()
# error: JNI_GetCreatedJavaVMs returned -1
I first tried reinstalling the Java JDK with an up-to-date version:
> [Downloaded and installed Java 8 JDK (Java SE Development Kit 8u121)](
Then reconfiguring R from the command line:
R CMD javareconf
This failed with the same error. A stackoverflow post (that I didn't save) suggested installing and compiling rJava from source, then installing your package. Similarly, [this SO post]( suggested that the issue my colleague came across was due to mismatched compiler and runtime version (possibly with the runtime version being older than the compiler).
So now that I updated the compiler and runtime environment (JDK) and reconfigured R, I tried installing rJava from source, then installing RWeka. --- SUCCESS!
install.packages("rJava", type = 'source') # Success!
install.packages("RWeka") # Success!
I didn't save the original error, but my experience on Linux was similar. I installed rJava from the Ubuntu repos: `sudo apt-get install r-cran-rjava`; installed the latest open-source JDK: `sudo apt-get install openjdk-jdk`; reconfigured R `sudo R CMD javareconf`; and installed RWeka from in R: `install.packages("RWeka")`.
**macOS details**
# R version 3.3.3 (2017-03-06)
# Platform: x86_64-apple-darwin13.4.0 (64-bit)
# Running under: macOS Sierra 10.12.3
# locale:
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
# other attached packages:
# [1] nvimcom_0.9-27 knitr_1.15.1 colorout_1.1-2
# loaded via a namespace (and not attached):
# [1] tools_3.3.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment