Spotfire® Enterprise Runtime for R

Using TERR, the terrJava Package, and Java

The terrJava package is included in Spotfire® Enterprise Runtime for R ( a/k/a TERR™) .

The terrJava package supports calls between Java code and TERR™ code in both directions:

  • R code within TERR can call Java static methods using the .JavaMethod function.
  • A Java application can start an embedded TERR engine and send expressions to be parsed and evaluated in TERR.
  • A Java application can spawn a separate Java process with an embedded TERR engine, and control it just as if it were embedded in the same process.

Initially, we created this package for internal use only to support running TERR engines within the Spotfire® Statistics Services server. However, others have expressed an interest to use terrJava to embed TERR in other Java applications. This document provides pointers so programmers can try this embedding using TERR and terrJava.

Note: The terrJava package is subject to change. If the current package does not supply everything that programmers need, the TERR development group would like know, so we can improve and extend terrJava.

This document is divided into three main sections:

  • Calling from TERR into Java.
  • embedding TERR within Java.
  • Spawning a separate Java process with an embedded TERR engine.

We suggest that a new user review these sections in order, testing that calling Java from TERR works correctly before trying the more complex task of embedding TERR within a Java process. This can be done by creating multiple Java processes with embedded TERR engines and managing communication between them. Alternatively, one can use the TerrJavaRemote class to spawn and control multiple processes with embedded TERR engines, as described in Setting up environment variables for a Java application to use Spotfire Enterprise Runtime for R.