Call a java method in R using rJava

2019-05-24 09:05发布

I use rJava to call a java code from R, trying to call an algorithm from SPMF tool. I tried to use a wrapper function as in this question, but this did not work with the SPMF code.

this is my R code:

   library(rJava)
   .jinit()
   .jaddClassPath ( "C:/mydrive/eclipse-workspace/myfile/src")
   print(.jclassPath())
   obj <- .jnew("AlgoFPGrowth_Strings")
   s <- .jcall(obj, returnSig= "V", method="runAlgorithm", 
   "input.csv","output.txt") ,  0.4 )

it gives me error ,method runAlgorithm with signature (D)V not found

this is the main in java:

    public static void main(String[] args) throws Exception {
    AlgoFPGrowth_Strings fpwindow=new AlgoFPGrowth_Strings();
    String input="input.csv";
    String output="output.txt";
    double minsupp = 0.4; 
    fpwindow.runAlgorithm( input,  output,  minsupp);
    fpwindow.printStats();

} 

I tried to change returnSig value into S and Ljava/lang/String; but I got the same error, could not find the method

when I apply the code on different java code with simple method it works, is there any idea how can I change my code?

标签: java r rjava
1条回答
Lonely孤独者°
2楼-- · 2019-05-24 09:39

Try the below methods,

  1. Change your jclassPath, where you directly specify the complete pathname of your jar file including the jar name, say /home/user/mypath/myclass_name.jar

  2. Or, you can unzip your jar file in a folder and refer to that path in your jclassPath.

If, the above does not work,

  1. Try to write the 'runAlgorithm' method in the same class where you are calling. I have faced issues with calling external libraries/classes.
查看更多
登录 后发表回答