0% found this document useful (0 votes)
23 views

Rcaller: A Java Package For Interfacing R: Mehmet Hakan Satman and Kopilov Aleksandr

Uploaded by

Testau
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Rcaller: A Java Package For Interfacing R: Mehmet Hakan Satman and Kopilov Aleksandr

Uploaded by

Testau
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

RCaller: A Java package for interfacing R

Mehmet Hakan Satman1 and Kopilov Aleksandr2


1 Department of Econometrics, Istanbul University, Istanbul, Turkey 2 Department of Mathematical
Optimization and Modeling, BIA-Technologies, Saint Petersburg, Russian Federation
DOI: 10.21105/joss.02722
Software
• Review
Summary
• Repository
• Archive
In this paper, version 3.0 of the open source library RCaller is introduced. RCaller is a software
library which simplifies performing data analysis and statistical calculations in Java using R.
Editor: Mikkel Meyer Andersen
The details are hidden from users including transferring data between platforms, function calls,
and retrieving results. In addition to previous RCaller versions, RCaller 3.0 implements the
scripting API of Java, ensuring R function calls and data transfers are performed in a standard
Reviewers:
way, as is usual for other scripting languages in Java. Besides implementation of new features,
• @xin-huang RCaller has many performance improvements in the new release of 3.0 (Satman & Curcean,
• @nthomasCUBE 2016).
Submitted: 24 August 2020
Published: 10 November 2020
State of the field
License
Authors of papers retain
copyright and release the work Nowadays, increased interest in statistical computation and data analysis has enhanced the
under a Creative Commons popularity of some programming languages such as R, Python, and Julia. As a result of
Attribution 4.0 International popularity, hundreds of packages are developed for these targeted languages. On the other
License (CC BY 4.0). side, many mainframe languages and their packages are adopted for general-purpose tasks in
several platforms. Interaction between those languages became a major requirement due to
the lack of modern statistical tools written in the general-purpose languages such as Java.
Renjin (Bertram, 2013) is a great effort for interfacing R from within Java using a different
perspective: Writing R from scratch in Java! GraalVM (Niephaus et al., 2019) is an other
admirable attempt for interfacing Python and R in Java with its polyglot design. Many tools
and software packages are developed for interfacing R and Java. Each one stands out with
its different features including speed, installation procedures, learning speed, and ease of use.

Statement of need

RCaller is a Java library for interfacing R from within Java (Satman, 2014). R is a popular
programming language and a programming environment with hundreds of packages written in
C, C++, Fortran, and R itself (R Core Team, 2020). This huge collection of computation tools
is not directly accessible for the other languages, especially for Java. RCaller supplies a clean
API for calling R functions, managing interactions, and transfering objects between languages.
There are other options in the literature including Rserve (Urbanek, 2003) and rJava (Urbanek,
2009) which are based on TCP sockets and JNI (Java Native Interface), respectively. RCaller
provides a set of easier calling schemes without any dependencies. Previous works showed
that the performance of the library is suitable for more cases, and studies with moderate
datasets can be handled in reasonable times (Satman & Curcean, 2016). Following its first
publication (Satman, 2014), support for DataFrame objects, R start-up options, automatic
Rscript executable locator, and Java Scripting API (JSR 223) have been implemented.

Satman et al., (2020). RCaller: A Java package for interfacing R. Journal of Open Source Software, 5(55), 2722. https://doi.org/10.21105/ 1
joss.02722
R has many well-tested and mature packages including for automatic time series model selec-
tion, clustering, segmentation and classification, non-linear and robust regression estimations,
data and text mining, linear and non-linear programming, generating plots, multivariate data
analysis, and function optimization. RCaller brings all of the functionality that R provides in
Java. RCaller is also used as a core of RCallerService (Kopilov, 2020), a free microservice
solution for running R-scripts from any other languages using HTTP.

Java scripting interface

RCaller also implements the scripting API of Java (JSR 223) after version 3 and above. In
other words, the engine behaves like a Java implementation of R. With this feature of RCaller,
calling R from Java is seemingly the same as in the other JSR 223 implementations such as
JavaScript, Python, Groovy, and Ruby. However the performance is not directly comparable
with native counterparts (Rhino, Jython, JGroovy, JRuby, etc.) since the target language is
not reimplemented in Java. Here is an example of sorting a Java array in R side and handling
the result in Java:

ScriptEngineManager manager = new ScriptEngineManager();


ScriptEngine en = manager.getEngineByName("RCaller");

try {
double[] a = new double[] {19.0, 17.0, 23.0};
en.put("a", a);
en.eval("sortedA <- sort(a)");
double[] result = (double[])en.get("sortedA");
System.out.println(result[0]);
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

RCaller, as a scripting engine in Java, creates an R process, encodes Java objects to XML,
runs commands in R side, gets back the results as XML, and parses the result to Java objects.
Since a single R process is created and used for consecutive calls, XML parsing is the only
calculation overhead.

Acknowledgements

We acknowledge contributions from Paul Curcean, Miroslav Batchkarov, Joel Wong, Kejo
Starosta, Steven Sotelo, Edinei Piovesan, Simon Carter, and others of this project.

References

Bertram, A. (2013). Renjin: A new r interpreter built on the jvm. The R User Conference,
useR! 2013 July 10-12 2013 University of Castilla-La Mancha, Albacete, Spain, 10, 105.
Kopilov, A. (2020). RCallerService — microservice for running r-scripts by http. https:
//github.com/Kopilov/RCallerService
Niephaus, F., Felgentreff, T., & Hirschfeld, R. (2019). Towards polyglot adapters for the
graalvm. Proceedings of the Conference Companion of the 3rd International Conference on

Satman et al., (2020). RCaller: A Java package for interfacing R. Journal of Open Source Software, 5(55), 2722. https://doi.org/10.21105/ 2
joss.02722
Art, Science, and Engineering of Programming, 1–3. https://doi.org/10.1145/3328433.
3328458
R Core Team. (2020). R: A language and environment for statistical computing. R Foundation
for Statistical Computing. https://www.R-project.org/
Satman, M., & Curcean, P. (2016). RCaller 3.0: An easy tool for abstraction of java and
r connectivity. https://github.com/jbytecode/rcaller/blob/master/doc/rcaller3/rcaller3.
pdf
Satman, M. H. (2014). RCaller: A software library for calling r from java. Journal of
Advances in Mathematics and Computer Science, 2188–2196. https://doi.org/10.9734/
bjmcs/2014/10902
Urbanek, S. (2009). How to talk to strangers: Ways to leverage connectivity between r, java
and objective c. Computational Statistics, 24(2), 303–311. https://doi.org/10.1007/
s00180-008-0132-x
Urbanek, S. (2003). A fast way to provide r functionality to applications. Proceedings of Dsc,
2.

Satman et al., (2020). RCaller: A Java package for interfacing R. Journal of Open Source Software, 5(55), 2722. https://doi.org/10.21105/ 3
joss.02722

You might also like