

When accessing R through Rserve from a java application, often one must take into account the communication and computation delay. Of course one should take into consideration network traffic and optimization when passing large amounts of data. Pass the name or IP address of the server to the RConnection constructot to access a remote server. Rserve can run locally or on a remote server accessible by multiple clients. Of course, more complex calculations can be made, as well as accessing installed packages. Here, the java code passes an array of doubles to R, the calculates the mean and standard deviation of the values. Public static void main(String args) throws Exception The Java Clientįrom Java, accessing Rserve requires adding the appropriate Rserve jars to the classpath, instantiating an instance of RConnection, then performing evaluations - the code of which is evaluated with R, the result of which is passed back to the java application. Briefly, one must first download the Rserve package in R, followed by starting the R server by loading the library and calling the Rserve() function, or running Rserve as a daemon via the command line using the 'R CMD Rserve' syntax. The Rserve webpage gives details for how one goes about installing and starting the server.

Rserve is a great alternative to facilitate pluging R into java applications.

Although one can attempt to automate R via Runtime.exec, doing so can be exception prone and can limit how one accesses R to single calls. Accessing the statistical power of R within java applications can sometimes be a powerful technique.
