[R] Using Java methods in R
hill0093
hill0093 at umn.edu
Mon Apr 25 14:27:24 CEST 2011
So the first few posts show that I found out how to
get Java functions to return type double numbers to R.
The arrays are still a problem.
Here is another of my attempts to understand how to get java arrays into R.
The Java code in class CalqsLin for an array
of constants named conArr and for a function returning an array is:
public static double[][]conArr=new double[][] { { 10001,10002,10003,10004
},{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } };
public final static double[][] arReturnTEST() {
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);
}
I evidently do not know how to retrieve them in R, even with .jevalArray():
> arj34Ret <- .jcall(qsLin,returnSig="[[D","arReturnTEST")
> ar34Ret <- .jevalArray(arj34Ret)
Error in .jevalArray(arj34Ret) :
object is not a Java object reference (jobjRef/jarrayRef).
> connArr <- .jevalArray(qsLin.conArr)
Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found
I need help from someone who calls Java from R.
The whole session was:
> library(rJava)
> .jinit()
> .jaddClassPath("C:/ad/j")
> print(.jclassPath())
[1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\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
> 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
> arj34Ret <- .jcall(qsLin,returnSig="[[D","arReturnTEST")
> ar34Ret <- .jevalArray(arj34Ret)
Error in .jevalArray(arj34Ret) :
object is not a Java object reference (jobjRef/jarrayRef).
> connArr <- .jevalArray(qsLin.conArr)
Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found
>
--
View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3473023.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list