I am trying to invoke some r code from within Java,pretty much like this:
private void makeMatrix() throws ScriptException {
try {
Runtime.getRuntime().exec(" Rscript firstscript.r");
System.out.println("Script executed");
} catch (IOException ex) {
System.out.println("Exception");
System.out.println(ex.getMessage());
}
}
Well, I get the "Script executed" print.
My (well, not really mine, just to test) r-Code is fairly simple, pretty much just to see it works at all:
x=seq(0,2,by=0.01)
y=2*sin(2*pi*(x-1/4))
plot(x,y)
So, it should not do much more than plot a sinus.
However, should not there be some kind of popup where you can actually see the plot? because there is none. What am I doing wrong?
Edit: In response to the comments I got here I edited the r-file, adding:
jpeg('rplot.jpg')
plot(x,y)
dev.off()
to it.
However, If I then try to find rplot.jpg on my system it simply is not there.
quartz, on Windows it iswindows, on *nix I believe you wantX11. It may make more sense to save the plot to a file using, e.g.,pngand then open the file from Java.execand build theProcessusing aProcessBuilder. Also break aString argintoString[] argsto account for arguments which themselves contain spaces.