0

How to call java method which returns list from R Language.

1 Answers1

1

You can do it with rJava package.

install.packages('rJava')
library(rJava)
.jinit()
jObj=.jnew("JClass")
result=.jcall(jObj,"[D","method1")

Here, JClass is a Java class that should be in your ClassPath environment variable, method1 is a static method of JClass that returns double[], [D is a JNI notation for a double array. See that blog entry for details.

cyberj0g
  • 3,707
  • 1
  • 19
  • 34
  • Glad it helped. If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. – cyberj0g Jun 22 '15 at 07:40
  • I downloaded the HelloJavaWorld package , I followed the steps by calling library(helloJavaWorld) which made it work. I am trying to call through your step normal class which I created through eclipse. But I am getting ClassNotFoundException .How can I make that class to be in classpath environment variable . I have set the classPath in environment variable which is pointing to lib folder of jdk – shwetanshusagar Jun 22 '15 at 08:09
  • Your ClassPath should have both JDK's \lib folder and folder with your compiled .jar file (or .class) split with ';' – cyberj0g Jun 22 '15 at 08:14