How to call Java main method using rJava package?
On Jan 16, 2013, at 7:32 AM, Gaurav Dasgupta wrote:
Hi,
I am trying to integrate my Java program with R using rJava package. I want
to execute the whole Java program from R. The main() method in my Java code
calls all the other defined methods. So, I guess I have to call the main()
method in .jcall.
An example Java code:
*class A {
public static int mySum(int x, int y) {
return x+y;
}
public static void main (String[] arg) {
System.out.println("The sum is " + mySum(2, 4));
}
}*
I can do the following to call the mySum() method:
*.jcall(obj, "I", "mySum", as.integer(2), as.integer(4))*
This will give the output *6*.
But can some one explain me that how exactly I can execute this program to
print *The sum is 6* from R? OR how can I call the main method?
.jcall("A","V","main",.jarray(list(), "java/lang/String")
But note that System.out is sent to stdout by Java so it won't output in the R console as R output so you should really avoid it.
You may consider using the stats-rosuda-devel mailing list for rJava questions.
Cheers,
Simon
I am a beginner in R. Thanks, Gaurav [[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel