I need to learn how to set up two methods (java functions) so I can call them
from R.
Currently I just copy and paste R code into the R console.
A little piece of the R code inside a loop is:
linTm <- linTimOfCalStg(dta[i,timCol],tlev)
calCk <- calStgOfLinTim(linTm,tlev)
if(calCk!=dta[i,timCol]) {
print(c(i,dta[i,timCol],linTm,calCk),digits=20)
stop("incorrect time conversion")
}
The two functions called have these first lines:
linTimOfCalStg <- function(calStg,tlev) and
calStgOfLinTim <- function(linTm, tlev)
which in java substitutes are:
public final static double linTimOfCalqsStg(String calStg,int tlev) and
public final static String calqsStgOfLinTim(double linTm,int tlev)
both in a java class called "CalqsLin.class" compiled from
"CalqsLin.java".
The R code works.
The purpose of all this is to eliminate duplicate subroutines and
their duplicate checking ln both languages.
There will be several other subroutines that I will also use in both
languages.
I can start by putting everything into a single directory in Windows seven
to learn.
How do I make this substitution?
--
View this message in context:
http://r.789695.n4.nabble.com/How-do-I-use-simple-calls-to-java-methods-tp4678753.html
Sent from the R help mailing list archive at Nabble.com.
I am surprised to not get a reply.
I suppose this means that extremely few, if any, use rJava.
rJava.pdf says this, but I am too stupid to interpret it:
Description
.jcall calls a Java method with the supplied arguments.
Usage
.jcall(obj, returnSig = "V", method, ..., evalArray = TRUE,
evalString = TRUE, check = TRUE, interface = "RcallMethod",
simplify = FALSE, use.true.class = FALSE)
Perhaps it means that to replace:
calCk <- calStgOfLinTim(linTm,tlev)
and use something like:
calCk <- .jcall(CalqsLin.class,returnSig = "S",
calStgOfLinTim(linTm,tlev),evalArray=FALSE,
evalString = TRUE, check = TRUE, interface = "RcallMethod",
simplify = FALSE, use.true.class = TRUE)
I suppose there are other setup things to do,
like start the JVM (java Virtual machine)
and I don't know what obj means.
Anyway, if I am able to do these simple java method calls,
it will be a big plus to our data analysis lab to use R conveniently.
Please help
--
View this message in context:
http://r.789695.n4.nabble.com/How-do-I-use-simple-calls-to-java-methods-tp4678753p4678786.html
Sent from the R help mailing list archive at Nabble.com.
Thanks so much for the reply. I did the search for "rJava examples" and found the Scott Hoover instructions which seemed like exactly what I needed. I compiled the java code and copied myExchange.java and myExchange.class to the directory where I started R where I did and the calls suggested inside worked. But there are no parameters passed in the examples. I need to do something like this: dateStg <- "201310221439591234" dateStg doubleLin <- .jcall(CalqsLin, "D", "linTimOfCalqsStgIsLev",dateStg,-4) or doubleLin <- .jcall(CalqsLin, "D", "linTimOfCalqsStgIsLev","201310221439591234",-4) where the latter two parameters are passed to linTimOfCalqsStgIsLev. Neither way works and I cannot understand the .jcall() instructions in rJava.pdf well enough. I'll keep trying, but would like help. -- View this message in context: http://r.789695.n4.nabble.com/How-do-I-use-simple-calls-to-java-methods-tp4678753p4678834.html Sent from the R help mailing list archive at Nabble.com.