[R] Copying to R a rectangular array from a Java class
Hurr
hill0093 at umn.edu
Sat Apr 30 18:27:34 CEST 2011
Bare test code: My simple Java test class source and R test code follow:
public class RJavTest {
public static void main(String[]args) { RJavTest rJavTest=new RJavTest();
}
public final static String conStg="testString";
public final static double con0dbl=10000001;
public final static double[]con1Arr=new double[] {
10001,10002,10003,10004,10005,10006 };
public final static double[][]con2Arr=new double[][] { { 101,102,103,104
},{ 201,202,203,204 },{ 301,302,303,304 } };
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") # a directory on my disk
print(.jclassPath())
rJavaTst <- .jnew("RJavTest") # compilation of class code
connStg <- .jfield(rJavaTst,sig="S","conStg")
print(connStg)
connStgRet <- .jcall(rJavaTst,returnSig="S","retConStg")
print(connStgRet)
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,digits=15)
# The above is just for education, question on rectangular is below
conn2Arr <- .jfield(rJavaTst,sig="[[D","con2Arr")
conn2ArrRet <- .jcall(rJavaTst,returnSig="[[D","retCon2Arr")
# I can't identify any complaints so far
print(conn2Arr)
print(conn2ArrRet)
The results are:
> library(rJava)
> .jinit()
> .jaddClassPath("C:/ad/j") # a directory on my disk
> print(.jclassPath())
[1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java"
[2] "C:\\ad\\j"
> rJavaTst <- .jnew("RJavTest") # compilation of class code
> connStg <- .jfield(rJavaTst,sig="S","conStg")
> print(connStg)
[1] "testString"
> connStgRet <- .jcall(rJavaTst,returnSig="S","retConStg")
> print(connStgRet)
[1] "testString"
> conn1Arr <- .jfield(rJavaTst,sig="[D","con1Arr")
> print(conn1Arr)
[1] 10001 10002 10003 10004 10005 10006
> print(conn1Arr[2])
[1] 10002
> conn1ArrRet <- .jcall(rJavaTst,returnSig="[D","retCon1Arr")
> print(conn1ArrRet)
[1] 10001 10002 10003 10004 10005 10006
> print(conn1ArrRet[2])
[1] 10002
> conn0dbl <- .jfield(rJavaTst,sig="D","con0dbl")
> print(conn0dbl,digits=15)
[1] 10000001
> # The above is just for education, question on rectangular is below
> conn2Arr <- .jfield(rJavaTst,sig="[[D","con2Arr")
> conn2ArrRet <- .jcall(rJavaTst,returnSig="[[D","retCon2Arr")
> # I can't identify any complaints so far
> print(conn2Arr)
[[1]]
[1] "Java-Array-Object[D:[D at 66848c"
[[2]]
[1] "Java-Array-Object[D:[D at 8813f2"
[[3]]
[1] "Java-Array-Object[D:[D at 1d58aae"
> print(conn2ArrRet)
[[1]]
[1] "Java-Array-Object[D:[D at 66848c"
[[2]]
[1] "Java-Array-Object[D:[D at 8813f2"
[[3]]
[1] "Java-Array-Object[D:[D at 1d58aae"
>
But what meaning should get from these strange messages?
--
View this message in context: http://r.789695.n4.nabble.com/Copying-to-R-a-rectangular-array-from-a-Java-class-tp3486167p3486167.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list