[R] Calling R from Java

Laetitia Marisa lmarisa at pasteur.fr
Thu Nov 21 17:28:45 CET 2002


As Jason Turner told you, one possibility is to use the communication 
interface SJava  (for another documentation, see this article: Urbanek, 
S. (2002)
"No need to talk to strangers - Cooperation of Interactive Software with 
R as Moderator",   
http://simon.urbanek.info/simon/yawe/research/pub.html) but it seems not 
so easy to use (but if you want to do sophisticated things from what 
I've heard you should use SJava).

Here are other alternatives that are easy to implement and that you 
should consider depending on what you want to do:

1- one is to use R in batch mode ie you create a file in your java code 
with all the R commands and send it to R (via Process 
pc=Runtime.getRuntime().exec(Rcall); )and then R creates an outputfile 
with all the results.
The matter with this is that there is no interactivity, variables are 
not kept, you have to parse the outputfile, ... (see the above article 
(see § FFinterface))

2- another one is to use the R server developed by Simon Urbanek:

http://stats.math.uni-augsburg.de/Rserve/

A java frontend is provided with the server, which allows to communicate 
easily with R and which sends back results in a java object. So for each 
connection to the server you have a R environment where all the variable 
generated are kept until you close the connection and from you java code 
it is as simple as this example: REXP mean = 
c.eval("mean"+i+"<-apply("+data+"[,data.cl=="+(i-1)+"],1,mean.na)");

This is what I'am using in my application and I am quite satisfied with 
it.


Hope this helps,

Laetitia.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1692 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20021121/af3efc2a/attachment.bin


More information about the R-help mailing list