[R] calling java from R and using java time series double precision array
Hurr
hill0093 at umn.edu
Sat Mar 24 14:09:05 CET 2012
No response, and I still cannot do it or find out where to learn.
JAVA CLASS SOURCE FOR R:
public class Transf2R {
Transf2R transf2R;
public static void main(String[]args) {
Transf2R transf2R=new Transf2R(); transf2R.transf2R=transf2R;
transf2R.transf2R.main2();
}
public final static void main2() {
//no code yet
}
public final static double con0dbl=10001;
public final static double[]con1Vec=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 double[][]arReturnMethod() {
double[][]retArr=new double[3][4]; for(int i=0;i<3;i++)for(int
j=0;j<4;j++)retArr[i][j]=i*1000+j; return(retArr);
}
public final static double[][]dbl2DimArRet4R(double[][]dbl2DimAr4R) {
return(dbl2DimAr4R); }
public final static double[]dbl1DimVcRet4R(double[]dbl1DimVc4R) {
return(dbl1DimVc4R); }
public final static double dblRet4R(double dbl4R) { return(dbl4R); }
public final static double dblNum4R=Math.PI;
}
R RUN OUTPUT:
> library(rJava)
> .jinit()
> .jaddClassPath("C:/ad/j")
> print(.jclassPath())
[1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.13\\rJava\\java"
[2] "C:\\ad\\j"
> trnsfer2R <- .jnew("Transf2R")
> arj3x4Ret <- .jcall(trnsfer2R,returnSig="[[D","arReturnMethod")
> print(arj3x4Ret)
[[1]]
[1] "Java-Array-Object[D:[D at 8813f2"
[[2]]
[1] "Java-Array-Object[D:[D at 1d58aae"
[[3]]
[1] "Java-Array-Object[D:[D at 83cc67"
> arj3x4Ret <-
> sapply(.jcall(trnsfer2R,returnSig="[[D","arReturnMethod"),.jevalArray)
> print(arj3x4Ret) # note: row and column indices get interchanged
[,1] [,2] [,3]
[1,] 0 1000 2000
[2,] 1 1001 2001
[3,] 2 1002 2002
[4,] 3 1003 2003
> dblNum <- .jcall(trnsfer2R,returnSig="D","dblRet4R",trnsfer2R$dblNum4R)
> print(dblNum,digits=20)
[1] 3.141592653589793116
> conn1Vec <-
> .jcall(trnsfer2R,returnSig="[D","dbl1DimVcRet4R",trnsfer2R$con1Vec) #
> con1Vec is java one dim array of double precision constants
> print(conn1Vec)
[1] 10001 10002 10003 10004 10005 10006
> conn2Arr <-
> .jcall(trnsfer2R,returnSig="[[D","dbl2DimArRet4R",trnsfer2R$con2Arr) #
> con2Arr is java two dim array of double precision constants
Error in .jcall(trnsfer2R, returnSig = "[[D", "dbl2DimArRet4R",
trnsfer2R$con2Arr) :
method dbl2DimArRet4R with signature ()[[D not found
> conn2Arr <-
> sapply(.jcall(trnsfer2R,returnSig="[[D","dbl2DimArRet4R",trnsfer2R$con2Arr),.jevalArray)
> # con2Arr is java two dim array
Error in .jcall(trnsfer2R, returnSig = "[[D", "dbl2DimArRet4R",
trnsfer2R$con2Arr) :
method dbl2DimArRet4R with signature ()[[D not found
>
OBSERVATIONS AND QUESTIONS:
1) sapply( ,.jevalArray) made arj3x4Ret correct
2) sapply( ,.jevalArray) did not make conn2Arr correct
3) dblNum and conn1Vec did not need sapply()
4) returnSig="[[D" worked to get arj3x4Ret but not for conn2Arr
5) row and column indices get interchanged in arj3x4Ret
6) How do I transfer to dblNum, conn1Vec, and conn2Arr without the methods
in java?
7) For large two dimensional arrays, are there two simultaneous copies
clogging up small computer memory?
--
View this message in context: http://r.789695.n4.nabble.com/calling-java-from-R-and-using-java-time-series-double-precision-array-tp4494581p4501306.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list