HowToInstallRJava: Difference between revisions

From BRF-Software
Jump to navigation Jump to search
imported>StefanAlbaum
No edit summary
 
imported>StefanAlbaum
No edit summary
Line 51: Line 51:


(replace x.y-z with the actual version)
(replace x.y-z with the actual version)
and
to install the default version of the library which is probably the 32bit/x86 version of the library.
 
To compile a 64bit/amd64 version of rJava make sure that the following environment variables are set up correctly (please adjust):
 
<pre><nowiki>
JAVA=/vol/java-1.6/bin/amd64/java
JAVAH=/vol/java-1.6/bin/amd64/javah
JAVAC=/vol/java-1.6/bin/amd64/javac
JAR=/vol/java-1.6/bin/amd64/jar
JAVA_HOME=/vol/java-1.6/jdk1.6.0_17/jre
 
export JAVA
export JAVAH
export JAVAC
export JAR
export JAVA_HOME
 
R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/amd64/server:${JAVA_HOME}/lib/amd64:${JAVA_HOME}/../lib/amd64:$LD_LIBRARY_PATH
export R_JAVA_LD_LIBRARY_PATH
 
r_arch="amd64"
export r_arch
</nowiki></pre>
 
 
Afterwards, type


<pre><nowiki>
<pre><nowiki>
azteca# R --arch amd64 CMD INSTALL --libs-only rJava_0.8-7.tar.gz
azteca# R --arch amd64 CMD INSTALL --libs-only rJava_x.y-z.tar.gz
</nowiki></pre>
</nowiki></pre>


to install the amd64 version of rJava.
to install the amd64 version of the rJava libraries. This will not (should not) replace any shared resources.
 
Please note however: in some versions of rJava this did not work properly and only one of the necessary libraries - rJava.so - was build correctly while the corresponding libjri.so was missing. A simple (but rather ugly) solution to this problem is to compile both versions one after the other into a user-defined directory and than to copy the two libraries into one folder.


== Setting up the Environment ==
== Setting up the Environment ==

Revision as of 11:27, 29 November 2010

Short Installation Instructions for rJava

NOTE

rJava is a simple R-to-Java interface. It is comparable to the .C/.Call C interface. 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.

First, have a look at the RForge.net homepage and the instructions provided on the homepage: http://www.rforge.net/rJava/index.html

Make sure that R was configured with Java support. If not, try to re-configure R by using R CMD javareconf (in any case it should not harm):

azteca#  R CMD javareconf


Try to install rJava from within R:

> install.packages('rJava')

Only if this does not work, install rJava using the instructions provided below.


! The following information is meant for internal use at the CeBiTec. Any information in this document is provided without any warranty. !


Prerequisites

  • Java >= 1.6.x
  • R >= 2.11.x

R should be configured with --enable-R-shlib switch (which is the case by default). Please make sure that compiler and linker flags are set up appropriately (see [HowToBuildR_ForSolaris] for further details).

Obtaining the Sources

Download the newest version (Attention! check compatibility with installed R version) from RForge.net: http://www.rforge.net/rJava/files/

Installation

You need to be a privileged user to install rJava in the standard location of R libraries and Perl modules. At the console, type:


azteca#  R CMD INSTALL rJava_x.y-z.tar.gz

(replace x.y-z with the actual version) to install the default version of the library which is probably the 32bit/x86 version of the library.

To compile a 64bit/amd64 version of rJava make sure that the following environment variables are set up correctly (please adjust):

JAVA=/vol/java-1.6/bin/amd64/java
JAVAH=/vol/java-1.6/bin/amd64/javah
JAVAC=/vol/java-1.6/bin/amd64/javac
JAR=/vol/java-1.6/bin/amd64/jar
JAVA_HOME=/vol/java-1.6/jdk1.6.0_17/jre

export JAVA
export JAVAH
export JAVAC
export JAR
export JAVA_HOME

R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/amd64/server:${JAVA_HOME}/lib/amd64:${JAVA_HOME}/../lib/amd64:$LD_LIBRARY_PATH
export R_JAVA_LD_LIBRARY_PATH

r_arch="amd64"
export r_arch


Afterwards, type

azteca# R --arch amd64 CMD INSTALL --libs-only rJava_x.y-z.tar.gz

to install the amd64 version of the rJava libraries. This will not (should not) replace any shared resources.

Please note however: in some versions of rJava this did not work properly and only one of the necessary libraries - rJava.so - was build correctly while the corresponding libjri.so was missing. A simple (but rather ugly) solution to this problem is to compile both versions one after the other into a user-defined directory and than to copy the two libraries into one folder.

Setting up the Environment

For java applications to execute R commands from within compiled java you have to set LD_LIBRARY_PATH, and R_HOME:


R_HOME=/vol/r-2.11/lib/R # please adjust!
export R_HOME

R_JAVA_LIB=$R_HOME/library/rJava/jri

LD_LIBRARY_PATH=$R_HOME/lib:$R_JAVA_LIB:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH