Hurr
2012-Mar-22 04:53 UTC
[R] calling java from R and using java time series double precision array
I haven't had time to try using R for over a year, but have a colleage who wants to. We work with time series and our current version of our calendar-time subroutines in java converts both directions between linear time and calendar. We have used calendar time since year 1965 starting out then with Fortran. Calendar time can be CnYrMoDa | CnYrMoDaHr | CnYrMoDaHrMn | CnYrMoDaHrMnSc | CnYrMoDaHrMnScD | CnYrMoDaHrMnScDC | CnYrMoDaHrMnScDCM | CnYrMoDaHrMnScDCMQ. We use calendar time in string format and linear time numbers in double precision. Thus we can get to calendar quadiseconds (tenths of milliseconds), and we must always have thoroughly tested subroutines. Unit of linear time can be converted to: da | hr | mn | sc | ds | cs | ms | qs . Limiting this discussion to reading time series data into R, I believe I want to have R call a java method that reads a time series into a two dimensional array with the first column being the linear time and the other columns being the various time series data (functions) at those times. I am not sure that the double precision java array can be used by R. And I would appreciate any other comments about this kind of interface with java. -- View this message in context: http://r.789695.n4.nabble.com/calling-java-from-R-and-using-java-time-series-double-precision-array-tp4494581p4494581.html Sent from the R help mailing list archive at Nabble.com.
Hurr
2012-Mar-23 15:35 UTC
[R] calling java from R and using java time series double precision array
2012/3/23 Back again today at trying to learn R. These are the results of a run I made. I understand very little of this. sapply() helps me get the array returned from a method. Strings and doubles returned from a method don't seem to need sapply(). I want to learn how to fetch the constant array at the end of this run. I would like other education about this situation also.> 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"> qsLin <- .jnew("CalqsLin") > calStg <- "201104242359599999" > print(calStg)[1] "201104242359599999"> dblTim <- > .jcall(qsLin,returnSig="D","linTimOfCalqsStgIsLev",calStg,as.integer(-4)) > print(dblTim,digits=20)[1] 634709087999999.00000> calStg <- > .jcall(qsLin,returnSig="S","calqsStgOfLinTimIsLev",dblTim,as.integer(-4)) > print(calStg)[1] "201104242359599999"> dblTim <- > .jcall(qsLin,returnSig="D","linTimOfCalqsStgIsLev",calStg,as.integer(-4)) > print(dblTim,digits=20)[1] 634709087999999.00000> arj34Ret <- > sapply(.jcall(qsLin,returnSig="[[D","arReturnTEST"),.jevalArray) > #public final static double[][] arReturnTEST() { //this is the java > method used > # 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); > #} > print(arj34Ret) # notice that the first java index is the column in R > print[,1] [,2] [,3] [1,] 0 1000 2000 [2,] 1 1001 2001 [3,] 2 1002 2002 [4,] 3 1003 2003> connArr <- .jevalArray(qsLin.conArr) # conArr is java two dim array of > double precision constantsError in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found> #public static double[][]conArr= { { 1001,1002,1003,1004 }, { > 2001,2002,2003,2004 }, { 3001,3002,3003,3004 } }; > print(connArr)Error in print(connArr) : object 'connArr' not found>-- View this message in context: http://r.789695.n4.nabble.com/calling-java-from-R-and-using-java-time-series-double-precision-array-tp4494581p4499206.html Sent from the R help mailing list archive at Nabble.com.
Hurr
2012-Mar-24 13:09 UTC
[R] calling java from R and using java time series double precision array
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 constantsError 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 arrayError 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.
Hurr
2012-Mar-27 22:35 UTC
[R] calling java from R and using java time series double precision array
I solved some of my problems, but the one that remains is that reading the two-dimensional arrays into R transposes the matrix. The arrays I want to read are unequal interval time multi series with the first column being the times which are converted in java from calendar CnYrMoDaHrMnScDCMQ or CnYrMoDa and between to linear. What R programs do I use to plot and analyse this kind of time series? How can I prevent transpose. THIS IS THE JAVA CODE: public class Transf2R { Transf2R transf2R; public static void main(String[]args) { Transf2R transf2R=new Transf2R(); transf2R.transf2R=transf2R; transf2R.transf2R.main2(); } public static void main2() { double[][]arRet=arReturnMethod(); for(int i=0;i<9;i++) { for(int j=0;j<3;j++)System.out.print((int)con2Arr[i][j]+","); System.out.println(); } for(int i=0;i<9;i++) { for(int j=0;j<3;j++)System.out.print((int)arRet[i][j]+","); System.out.println(); } } 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 },{ 20001,20002,20003 },{ 30001,30002,30003 },{ 40001,40002,40003 } ,{ 50001,50002,50003 },{ 60001,60002,60003 },{ 70001,70002,70003 },{ 80001,80002,80003 } ,{ 90001,90002,90003 } }; public final static double[][]arReturnMethod() { double[][]retArr=new double[9][3]; for(int i=0;i<9;i++)for(int j=0;j<3;j++)retArr[i][j]=(i+1)*1000+j+1; 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; } WHICH PRODUCES THIS UPON RUNNING MAIN(): 10001,10002,10003, 20001,20002,20003, 30001,30002,30003, 40001,40002,40003, 50001,50002,50003, 60001,60002,60003, 70001,70002,70003, 80001,80002,80003, 90001,90002,90003, 1001,1002,1003, 2001,2002,2003, 3001,3002,3003, 4001,4002,4003, 5001,5002,5003, 6001,6002,6003, 7001,7002,7003, 8001,8002,8003, 9001,9002,9003, I FINALLY FIGURED OUT SOME R CODE THAT DEMONSTRATES WHAT I WANT TO DO:> library(rJava) # loads package > .jinit() # starts JVM[1] 0> .jaddClassPath("C:/ad/j") > print(.jclassPath())[1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.13\\rJava\\java" "C:\\ad\\j"> trnsfer2R <- .jnew("Transf2R") # creates link to java class > arj9x3Ret <- > sapply(.jcall(trnsfer2R,returnSig="[[D","arReturnMethod"),.jevalArray) > print(arj9x3Ret) # note: row and column indices get interchanged[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 1001 2001 3001 4001 5001 6001 7001 8001 9001 [2,] 1002 2002 3002 4002 5002 6002 7002 8002 9002 [3,] 1003 2003 3003 4003 5003 6003 7003 8003 9003> 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 <- > sapply(.jcall(trnsfer2R,returnSig="[[D","dbl2DimArRet4R",.jfield(trnsfer2R, > "[[D", "con2Arr", convert=F)),.jevalArray) > print(conn2Arr)[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 10001 20001 30001 40001 50001 60001 70001 80001 90001 [2,] 10002 20002 30002 40002 50002 60002 70002 80002 90002 [3,] 10003 20003 30003 40003 50003 60003 70003 80003 90003>BUT THE TWO-DIMENSIONAL ARRAYS SEEM TO BE TRANSPOSED. -- View this message in context: http://r.789695.n4.nabble.com/calling-java-from-R-and-using-java-time-series-double-precision-array-tp4494581p4510410.html Sent from the R help mailing list archive at Nabble.com.