[R] Copying to R a rectangular array from a Java class

Hurr hill0093 at umn.edu
Mon May 2 14:27:01 CEST 2011


I discovered that a row of a rectangular array returns, but a function
parameter is not sent to Java.
Appended 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[] retCon2Row0() { return(con2Arr[0]); } 
  public final static double[] retCon2Row(int row) { return(con2Arr[row]); } 
  public final static double[][] retCon2Arr() { return(con2Arr); } 
}
library(rJava)
.jinit()
.jaddClassPath("C:/ad/j") # a directory on my disk 
print(.jclassPath())
rJavaTst <- .jnew("RJavTest") # compiled java to class file
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)
conn2Row0Ret <- .jcall(rJavaTst,returnSig="[D","retCon2Row0")
print(conn2Row0Ret)
print(conn2Row0Ret[2])
# The above is education, questions on rectangular and parameters are 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)
conn2RowRet <- .jcall(rJavaTst,returnSig="[D","retCon2Row",0)
print(conn2RowRet)
print(conn2RowRet[2])
# But what meaning should I get from these strange messages? 

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") # compiled java to class file
> 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
> conn2Row0Ret <- .jcall(rJavaTst,returnSig="[D","retCon2Row0")
> print(conn2Row0Ret)
[1] 101 102 103 104
> print(conn2Row0Ret[2])
[1] 102
> # The above is education, questions on rectangular and parameters are
> 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"
> conn2RowRet <- .jcall(rJavaTst,returnSig="[D","retCon2Row",0)
Error in .jcall(rJavaTst, returnSig = "[D", "retCon2Row", 0) : 
  method retCon2Row with signature (D)[D not found
> print(conn2RowRet)
Error in print(conn2RowRet) : object 'conn2RowRet' not found
> print(conn2RowRet[2])
Error in print(conn2RowRet[2]) : object 'conn2RowRet' not found
> # But what meaning should I 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-tp3486167p3489899.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list