Installing rJava locally

For more information on how to install R packages locally, see .

To install the rJava package locally, you must load the OpenJDK module and set some environment variables.

To load both openjdk and r, run:

module load openjdk/18.0.1.1 r/4.2.2

The variables that need to be set up are:

export JAR="$JAVA_HOME/bin/jar" export JAVA="$JAVA_HOME/bin/java" export JAVAC="$JAVA_HOME/bin/javac" export JAVA_LIBS="-L$JAVA_HOME/lib/server -ljvm" export JAVA_CPPFLAGS="-I$JAVA_HOME/include -I$JAVA_HOME/include/linux" export JAVA_LD_LIBRARY_PATH="$JAVA_HOME/lib/:$JAVA_HOME/lib/server"

Finally, start an R session and install the package (assuming your local libraries are stored in ~/rlibs:

R .libPaths("~/rlibs") install.packages("rJava", lib = "~/rlibs", repo = "https://cloud.r-project.org/")

Once the package is installed, the environment variables don’t need to be set up every time you use it.