I use rJava to integrate Java and R in my project.
I need to load GWmodel R package in my application and calculate the distance matrix from Java.
This is my function to load GWmodel and calculating distance matrix :
Rengine engine = new Rengine(new String[] { "--no-save" }, false, null);
engine.eval("library(GWmodel)");
engine.eval("data(LondonHP)");
engine.eval("DM <- gw.dist(dp.locat=coordinates(londonhp))");
double[][] matrix = engine.eval("DM").asMatrix();
But the code result an error :
Exception in thread "main" java.lang.NullPointerException
at rjavaexm.RJavaExm.main(RJavaExm.java:30)
So, I want to know, is it possible to load R package and data using rJava from Java like code above?
Or are there any appropriate ways to do that?
I'm using maven so i have the following (generated from a simple maven project)
Select default choice.
pom.xml
App.java
Make sure package Rserve is installed in your R environment.
from R
with maven (command line, another shell)
We get with my settings :
Don't forget to close the Rserve server/process afterwards ...