Start United States USA — software Getting Started with R Using Java – Developer.com

Getting Started with R Using Java – Developer.com

202
0
TEILEN

NewsHubR is one of the most commonly used software packages for statistical computing and graphics and Java is the most commonly used programming language. rJava is a JNI (Java Native Interface)-based, R-to-Java interface with which Java objects may be created and Java methods called and Java fields accessed from R. In this tutorial, we shall get started with using the rJava R package to use Java from R. This tutorial has the following sections:
R is supported on Unix-like OS, Windows OS, and Mac OS X. Support for Mac OS Class was discontinued with R 1.7.1. We have used R on Windows OS for which you can download the binaries file.
Double-click the binaries file to install R on Windows (see Figure 1). After R has been installed, start R to log in to the R Console.
Figure 1: Installing R
Output the R version with the following command:
The R version 3.3.1 is used in his tutorial.
Create a simple R function to test R. The following hello function takes an arg for its name and outputs a hello message.
Invoke the R function with a name String.
A message gets output:
The hello function and its output is shown in R Console (see Figure 2).
Figure 2: The hello function and its output
To install the rJava package, run the following command:
The rJava package gets installed, as shown in Figure 3.
Figure 3: A successful installation
Before you are able to use any rJava functions, we need to initialize the JVM. The usage of.jinit is shown, as follows.
The classpath arg prepends additional classes to the CLASSPATH setting. The parameters arg specifies the parameters with which the virtual machine is to be invoked. The „… “ indicates other implementation specific to Java initialization parameters.
The „silent“ attribute is set to FALSE by default, indicating that no warnings are issued. Setting „force.init“ to TRUE would re-initialize the JVM if it is running. The.jinit returns 0 if the JVM got initialized and a -ve integer if it did not. A +ve integer is returned if the JVM got initialized partially. Before initializing the JVM, the rJava library must be loaded.

Continue reading...