Re: [R] Using Java methods in R

From: lcn <lcn918_at_gmail.com>
Date: Tue, 26 Apr 2011 09:57:09 +0800 (CST)

you should take a look at the doc of .jarray by input "?.jarray" in the console and see related examples by "example(.jarray)" in the console.

This is what the doc says, and your issues might be related to it:

     '.jevalArray' currently supports only a subset of all possible
     array types. Recursive arrays are handled by returning a list of
     references which can then be evaluated separately.

At 2011-04-25 20:27:24£¬hill0093 <hill0093_at_umn.edu> wrote:

>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.

        [[alternative HTML version deleted]]



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 Tue 26 Apr 2011 - 02:24:00 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 - 20:10: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