[R] Using Java methods in R

hill0093 hill0093 at umn.edu
Tue Apr 26 22:01:00 CEST 2011


Thanks Icn for pointing that out, but I don't understand it.
My use of .jcall to return a type double scalar or String worked.
My use of .jfield to get a one dimensional static array worked.
My use of .jfield to get a static scalar constant did not work.
My use of .jfield to get a two dimensional static constant array did not
work.
I don't understand the remainder of my rjava trial.

The C:/ad/j/CalqsLin java code is:
  public final static double con0dbl=10001; 
  public final static double[]con1Arr=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[][] 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 have the RGui with R Console on the screen; here is the trial:
On the top pullDowns: Packages > Install Packages > USA(IA)> rJava 
> library(rJava)
> .jinit()
[1] 0
> .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"
> conn1Arr <- .jfield(qsLin,sig="[D","con1Arr")
> print(conn1Arr)
[1] 10001 10002 10003 10004 10005 10006
> conn0dbl <- .jfield(qsLin,sig="D","con0dbl")
Error in .jfield(qsLin, sig = "D", "con0dbl") : 
  RgetField: field con0dbl not found
> arj34Ret <- .jcall(qsLin,returnSig="[[D","arReturnTEST")
> print(arj34Ret[2][3],digits=15)
[[1]]
NULL
> print(arj34Ret,digits=15)
[[1]]
[1] "Java-Array-Object[D:[D at 1d58aae"
[[2]]
[1] "Java-Array-Object[D:[D at 83cc67"
[[3]]
[1] "Java-Array-Object[D:[D at e09713"
> ar34Ret <- .jevalArray(arj34Ret)
Error in .jevalArray(arj34Ret) : 
  object is not a Java object reference (jobjRef/jarrayRef).
> print(ar34Ret[2][3],digits=15)
Error in print(ar34Ret[2][3], digits = 15) : object 'ar34Ret' not found
> print(ar34Ret,digits=20)
Error in print(ar34Ret, digits = 20) : object 'ar34Ret' not found
> 








--
View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3476371.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list