Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: rJava package install failing

Tags:

r

rjava

People also ask

What is rJava package in R?

rJava provides a low-level bridge between R and Java (via JNI). It allows to create objects, call methods and access fields of Java objects from R. rJava release versions can be obtained from CRAN - usually install. packages("rJava") in R will do the trick.

What is rJava?

rJava is a JNI (Java Native Interface)-based, R-to-Java interface with which Java objects may be created and Java methods called and Java fields accessed from R. In this tutorial, we shall get started with using the rJava R package to use Java from R. This tutorial has the following sections: Setting the Environment.


Wouldn't

apt-get install r-cran-rjava

have been easier? You could have asked me at useR! :)


Turns out my problem was an issue with my JAVA_HOME environment variable. Yes, shocking I know. My initial setting for PATH and JAVA_HOME looked like this:

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

And I added /jre so it now looks like this:

export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export PATH=$PATH:$JAVA_HOME/bin

Everything in Java seemed to work fine without the /jre but rJava would not. Odd.


That is how I make it work :

In Linux (Ubuntu 16.04 and 20.04 worked confirmed)

sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo R CMD javareconf

in R:

install.packages("rJava")

Thanks - your suggestion about $JAVA_HOME lead me to a similar solution:

unset JAVA_HOME

before invoking R.