# Installing the rJava Package

The rJava package gives access to low-level R functions to the Java interface, but it is not provided with TERR. These instructions help you prepare your computer to use rJava.

## Before you begin

The rJava package requires the following.

- A bit-matching (64-bit) version of Java, version 6 or later, is installed. (Tested with version 11.0.1.)
- The system variable JAVA_HOME is set. Follow the instructions for Setting JAVA_HOME if you are unsure.

Attention: These instructions are for installing the rJava package for use with TERR 4.2 or later. If you are using an earlier version, and you cannot update your version of TERR, see the release notes for more information for the verison of TERR you are running.

## About this task

Perform this task in the TERR console or in TERR running under RStudio.

## Procedure

1. At the command prompt, type `install.packages("rJava")`.
   The rJava package is installed from the package repository to the site-library directory.
2. At the command prompt, type `library(rJava)`.
   For example:

       > library(rJava)
       The following object(s) are masked _from_ 'package:utils':

           head, str, tail
       The following object(s) are masked _from_ 'package:methods':

           new, show
       The following object(s) are masked _from_ 'base':

           anyDuplicated, duplicated, rev, sort, unique

   The rJava package is now in your search path.
3. At the command prompt, type `searchpaths()`.
   For example:

       > searchpaths()
       [1] ".GlobalEnv"
       [2] "C:/Program
       			 Files/spotfire/terr61/site-library/rJava"
       [3] "C:/Program
       			 Files/spotfire/terr61/library/stats"
       [4] "C:/Program
       			 Files/spotfire/terr61/library/graphics"
       [5] "C:/Program
       			 Files/spotfire/terr61/library/grDevices"
       [6] "C:/Program
       			 Files/spotfire/terr61/library/utils"
       [7] "C:/Program
       			 Files/spotfire/terr61/library/methods"
       [8] "C:/Program
       			 Files/spotfire/terr61/library/base"

   The absolute file path is returned for each package in the current environment. Note that by default, the newly-loaded rJava is listed second in the search path.