Skip to content
Prev 13991 / 398502 Next

R and Java

Hi Olivier.

  For (what I believe are) technical reasons, if you get an error in R
before initializing the Java virtual machine (JVM), very bad things
happen when you do actually start Java via the .JavaInit() function.
So the thing to try is running R, and immediately loading the SJava
library and initializing the JVM. 
 (R
   > library(SJava)
   > .JavaInit()
)
Then things should be better and we can start dealing with any other problems.

The technical reasons that I believe are causing the problem are what
make the S-Java connection somewhat less stable than other
packages. Specifically they relate to the fact that Java and the
underlying implementation uses threads, while R does not. And all the
libraries that they share in common (libc, libm, ...) are slightly
different and whoever gets to load them first wins and sets the
environment for the other.  When running Java inside R, R wins.  On
Unix, you can run Java and call R from within Java. In that setup,
Java will load the correct libraries for itself and R will be happy
with the result.

As Andrew pointed out, setting the LD_LIBRARY_PATH environment
variable correctly is important. And ensuring that the same JVM is
used at run time as used at compile time is usually vital.  To to do
this, the package supplies two shell scripts (one for the C shell and
another for the Bourne shell) in the scripts/ directory which can be
sourced to set the necessary environment variables.

Hope this helps. I'm keen to hear about other problems.
 D.
Olivier Martin wrote:

  
    
Message-ID: <20011003102344.G1799@jessie.research.bell-labs.com>
In-Reply-To: <3BB99A45.7405CDBE@inrialpes.fr>; from olivier.martin@inrialpes.fr on Tue, Oct 02, 2001 at 12:43:17PM +0200