Rcaller: A Java Package For Interfacing R: Mehmet Hakan Satman and Kopilov Aleksandr
Rcaller: A Java Package For Interfacing R: Mehmet Hakan Satman and Kopilov Aleksandr
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.
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:
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