From simon.urbanek at r-project.org  Fri Jul 14 02:27:29 2006
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 13 Jul 2006 20:27:29 -0400
Subject: [Rd] Call R function from Java
In-Reply-To: <000001c6a6c3$53ebbe70$0100a8c0@kapelnerquad>
References: <000001c6a6c3$53ebbe70$0100a8c0@kapelnerquad>
Message-ID: <52C985BB-05CD-4062-851B-99E1019BB11A@r-project.org>

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



[Rd] Call R function from Java
Simon Urbanek