# [R] Using Java methods in R

hill0093 hill0093 at umn.edu
Fri Apr 29 16:47:53 CEST 2011

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

```