Skip to content

Installation

Joaquin Bedia edited this page May 30, 2016 · 49 revisions

The loadeR package relies on the powerful capabilities of the Unidata's netCDF-Java libraries. An in-house version of this open source software (v4.6-SNAPSHOT) is currently used by loadeR.java. The connection between R and Java is established through rJava. Thus, loadeR depends on the packages loadeR.java and rJava.

Installation steps

(1) Install the rJava package available on CRAN. See the information below if you find problems in this step.

(2) Install loadeR and the companion loadeR.java packages (requires the R package devtools):

devtools::install_github(c("SantanderMetGroup/loadeR.java", "SantanderMetGroup/loadeR"))

(3) The loadeR package requires Java version 1.7 or higher. In order to detect possible problems in advance, a message with the Java version used by R will be given on loadeR start. Check the startup messages and upgrade the Java version if a warning is given (see the information below if you find problems in this step).

We strongly recommend performing the installation directly from the default R GUI, to avoid further problems e.g. with RStudio. In Linux, system installation is recommended (e.g. in Debian-like systems sudo apt-get install r-cran-rjava).

Help for rJava installation problems

Because an adequate configuration of R and Java can be troublesome, as reported by some users, this section gives some basic information on how to proceed when things do not work fine on the first go.

In some cases, during the installation of rJava, an error message of this type may appear:

ERROR: configuration failed for package ‘rJava’

This type of error most often appears when R does not find Java support in your system. In other words, R can't figure out where Java is located in your system. In this case, the environment variable JAVA_HOME must be set to point to a specific JRE/JDK, either through the command line or within the R environment (this is detailed in the R documentation).

From R, it is possible to check the JAVA_HOME path by typing:

Sys.getenv("JAVA_HOME")

This will return an empty value if this variable is not set. We can manually set it within R using Sys.setenv, as follows (for instance a typical Windows path):

Sys.setenv(JAVA_HOME = "C:\\Program Files (x86)\\Java\jdk1.7.0\\jre")

or forcing the removal of the current JAVA_HOME:

Sys.setenv(JAVA_HOME = "")

After this, it is necessary to run R CMD javareconf from a terminal to update the settings (this requires superuser privileges in Linux, or alternatively running ~$ R CMD javareconf -e).

For instance, a typical setting for ‘x86_64’ Linux is

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-4.b16.fc21.x86_64/jre

Similarly, for missing JAVAC, JAVAH and JAR variables, a typical setting would be (Ubuntu 12.04 32bit):

~$ sudo R CMD javareconf JAVAC = '/usr/lib/jvm/java-7-openjdk-i386/jre/bin/java' JAR = '/usr/bin/jar' JAVAH = '/usr/bin/javah' 

This issue is discussed in more detail at the [http://r.789695.n4.nabble.com/rjava-JDK-not-found-td889163.html R-help forum]. Alternatively, in linux systems the problem has been reported to be overcome by using the [http://www.nongnu.org/synaptic/ Synaptic Package Manager] for library installation

Or for Windows:

JAVA_HOME=C:\\Program Files (x86)\\Java\jdk1.7.0\\jre

Or for Mac OSX

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre

Linux Systems

A useful thread for Debian and similar distributions (Ubuntu...) related to the configuration of Java is given here

Help on rJava package installation is given here

As a general rule, it is highly recommended to install rJava from the terminal, for instance using apt-get install or similar (instructions for different Linux distributions can be seen in this link):

~$ sudo apt-get install r-cran-rjava

MacOSX

Mac OS X comes with a preinstalled old Java version (1.6). In this case, even if a newer version of Java is installed, it is sometimes troublesome changing the default Java version to be used by R (or RStudio) to a newer one. You can see which version is used in an R session when loading the loadeR package (library('loadeR') gives a message with the Java version). If the old version (1.6) is loaded by default, try ~$ sudo R CMD javareconf (from the terminal)

and

install.packages('rJava', type='source') (from R)

This can sometimes solve the problem by opening R (or RStudio) from the terminal instead of directly clicking on the application icon

~$ R

~$ /Applications/RStudio.app/Contents/MacOS/RStudio

Note that the Java version accesible from RStudio and from the R application can be different, and different from the R application directly opened from the terminas (as shown above).

Sys.getenv("JAVA_HOME")

Some links with further information follow:

Windows

As Windows is by default installed for both 32 and 64 bit architectures, conflicts are usual. In order to adequately configure R and Java in Windows, the next steps should be followed:

  • As both directories, C:/Program Files and C:/Program Files (x86) exist, it may happen that R is looking for Java in one of them that does not hold the Java directory with a suitable Java version (see above). Then, it should match the R version we are running.
  • R (and RStudio if used) must work in the same architecture that the Java version. In RStudio, it is possible to set the R version in the Menu Tools --> Global options --> General
  • The right rJava version matching the selected architecture should be installed. This can be checked by inspecting the existence of the directory x64 or i386 within the rJava folder created when installing the package, typically in something like C:/Users/user/Documents/R/win-library/3.2/rJava.