From kornelius.rohmeyer at small-projects.de Fri Jun 12 15:36:57 2009 From: kornelius.rohmeyer at small-projects.de (Kornelius Rohmeyer) Date: Fri, 12 Jun 2009 15:36:57 +0200 Subject: [Biocep-commits] In callAndGetReference the R function is called twice Message-ID: <1244813817.7016.6.camel@triops> Dear Biocep mailing list, since there is no documentation yet for RServices perhaps it is as intended, but the following side effect caused problems for me: If I use DirectJNI.getInstance().getRServices() and call a function via call, then it is called only one time. But if I use callAndGetReference it is called twice. Here an example: import java.rmi.RemoteException; import org.kchine.r.server.RServices; public class BiocepTest { public static void main(String[] args) throws RemoteException { RServices rs = org.kchine.r.server.DirectJNI.getInstance().getRServices(); rs.sourceFromBuffer("x<-1;" + " mytest <- function(){print(paste(\"Test\",x));" + " x<<-x+1;}"); rs.call("mytest"); rs.callAndGetReference("mytest"); } } The output is: call str >>>mytest() + ------evalAndGetObject from :mytest() [1] "Test 1" call str >>>mytest() + ------evalAndGetObject from :mytest() [1] "Test 2" [1] "Test 3" The problem is due to calling the private method evalAndGetObject(String expression, boolean resultAsReference) with resultAsReference = true and expression still equal to "mytest()". The first evaluation of the expression "mytest()" is in the line: long resultId = e.rniEval(e.rniParse(expression, 1), 0); But a second evaluation occurs when javaClassName is guessed for the reference: String javaClassName = guessJavaClassRef(rclass, resultType, isS3Class(expression)); The whole second evaluation can be avoided by changing this line to: String javaClassName = guessJavaClassRef(rclass, resultType, isS3Class(resultvar)); I would be very glad if you would accept this patch. Best regards, Kornelius Rohmeyer.