Re: [Rd] Call R function from Java

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Fri 14 Jul 2006 - 00:27:29 GMT

Adam,

[I'm moving this discussion to stat-rosuda-devel, because JRI is strictly speaking a contributed package]

On Jul 13, 2006, at 5:28 PM, Adam Kapelner wrote:

> It worked. All I had to do is set PATH = < R directory > in my
> system variables in "My Computer" and that was it!
>
> Oh btw Simon, I couldn't find the run.bat in the JRI_0.2-4.tar.gz
> file. I found a "run.in" but that is a unix bash script.
>

run (and run.bat respectively) are created by make, so you should run "sh configure.win; make" on Windows or "./configure; make" on unix. The script must contain paths to your JRE and R, so it cannot be shipped directly in JRI - that's why it is created during the build phase instead.

> Another question:
>
> When I'm evaluating R expressions:
> REXP
> rexp3=r.eval("cancer=read.table(\"CancerCellsTrainingFile.txt
> \",header=TRUE,
> sep=\",\")");
> System.out.println(rexp3);
>
> I sometimes get back form the println:
> RXP[unknown/19, id=1208787616, o=null]
>
> Is there anyway to actually view that output as a string?

It is a generic vector (aka list). If you use JRI 0.3 (from http:// www.rosuda.org/R/nightly ), you can use
RVector v=rexp3.asVector()
for (Enumeration e = v.elements() ; e.hasMoreElements() ;) System.out.println(e.nextElement());

If you are using JRI 0.2 or earlier, you'll have to use something like this:
long[] l = r.rniGetVector(rexp3.xp);
int i=0; while(i<l.length) System.out.println(new REXP(r, l[i++]));

Cheers,
Simon



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Jul 14 10:32:11 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 14 Jul 2006 - 06:24:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.