Call a java method in R using rJava

我是研究僧i 提交于 2019-12-14 00:39:22

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/47016125/call-a-java-method-in-r-using-rjava

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!