Re: [R] Using Java methods in R

From: hill0093 <hill0093_at_umn.edu>
Date: Mon, 25 Apr 2011 05:27:24 -0700 (PDT)

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.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 25 Apr 2011 - 12:32:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 26 Apr 2011 - 02:30:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive