Re: [R] Using Java methods in R

From: hill0093 <>
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); } }

rJavaTst <- .jnew("RJavTest")
conn1Arr <- .jfield(rJavaTst,sig="[D","con1Arr") print(conn1Arr)
conn1ArrRet <- .jcall(rJavaTst,returnSig="[D","retCon1Arr") print(conn1ArrRet)
conn0dbl <- .jfield(rJavaTst,sig="D","con0dbl") print(conn0dbl)
##The above works, but not the following conn2Arr <- .jfield(rJavaTst,sig="[[D","con2Arr")


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

The latter 2-dim stuff doesn't work

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
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 Please read the posting guide before posting to the list.

list of date sections of archive