[R] Executing an R function from Java.

Duncan Temple Lang duncan at research.bell-labs.com
Sat Nov 11 19:33:25 CET 2000



   >>>>> "RP" == Richard Piper <rpiper at med.usyd.edu.au> writes:

       RP> Is anyone aware of a mechanism by which I could execute an R
       RP> function from within java (say a servlet).

  The RJava (http://www.omegahat.org/RSJava) package has all the
necessary pieces to do this.  Specifically, see the native eval()
method in the RForeignReference class.  For the reasons below, this
functionality is not in the most covenient form for calling R from
Java.  There are some documents on the web site above which might help
understand the interface.

Previously, the package was oriented towards calling Java methods from
R, not calling R functions from Java. But, of course, to be useful it
has to do the reverse, and it does using some cute tricks to generate
new Java classes on demand, leaves complex objects in the system they
were defined and exports references, etc.

Now that Kurt and I have "finished" getting the R as a shared library
on Unix working, embedding R in other applications/languages (Java,
Perl, Python, Postgres & MySQL, Apache) is quite easy.

 I can provide a Java class that provides more convenient access to
calling R functions from Java. It would help if you described a little
more about how you want to use it. The R/SPlus-Java interface is very
general and it doesn't really matter what functions you call. The
difficulty lies in what the caller expects to have happen when the
result of the R function is a complex object, e.g. a fitted model. The
RJava package has facilities to care of importing it into Java with
the correct class type. But the developer had better understand that
it actually makes sense to use the R object (reference) in subsequent
Java calls. In other words, the mechanics are there, but it is back to
thinking about what are the semantics. Damn, I thought we weren't
going to have to think :-)


 D.


  
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list