Re: [R] Using Java methods in R

From: hill0093 <hill0093_at_umn.edu>
Date: Fri, 29 Apr 2011 07:47:53 -0700 (PDT)

H do I obtain a strictly rectangular
type-double array (converted to an R 2-dimensional array) from a Java class? I can obtain a 1-dimensional type-double array (vector) or a scalar, but I cannot figure out the two-dimensional from the instructions. Is .jevalArray also involved?
My simple Java test class and R test code follows:

import java.lang.reflect.Array;
public class RJavTest {
  public static void main(String[]args) { RJavTest rJavTest=new RJavTest(); }
  public final static String conStg="testString";   public final static double con0dbl=10001;   public final static double[]con1Arr=new double[] { 10001,10002,10003,10004,10005,10006 };
  public final static double[][]con2Arr=new double[][] { { 10001,10002,10003,10004 },{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } };
  public final static String retConStg() { return(conStg); }   public final static double retCon0dbl() { return(con0dbl); }   public final static double[] retCon1Arr() { return(con1Arr); }   public final static double[][] retCon2Arr() { return(con2Arr); } }

library(rJava)
.jinit()
.jaddClassPath("C:/ad/j")
print(.jclassPath())
rJavaTst <- .jnew("RJavTest")
conn1Arr <- .jfield(rJavaTst,sig="[D","con1Arr") print(conn1Arr)
print(conn1Arr[2])
conn1ArrRet <- .jcall(rJavaTst,returnSig="[D","retCon1Arr") print(conn1ArrRet)
print(conn1ArrRet[2])
conn0dbl <- .jfield(rJavaTst,sig="D","con0dbl") print(conn0dbl)
##The above works, but not the following conn2Arr <- .jfield(rJavaTst,sig="[[D","con2Arr")

print(conn2Arr[2])
print(conn2Arr[2,3])
print(conn2Arr)

arj34Ret <- .jcall(rJavaTst,returnSig="[[D","arReturnTEST") print(arj34Ret)

The latter 2-dim stuff doesn't work

--
View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3483862.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 29 Apr 2011 - 14:51:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Apr 2011 - 15:00:34 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.

list of date sections of archive