#Data generating process
x<-rnorm(100, 0, 2)
#we generated a normal sample with mean 0 and standard deviation 2
png("path/to/file.png")
plot.ts(x)
dev.off()
After running this short script, no screen output is produced but path/to/file.png is created as a png image. After calling this script from Java, produced image can be loaded like this:
ImageIcon myIcon = new ImageIcon("/path/to/file.png");
This image can be easly drawn on a swing container using
public void paintComponent(Graphics g) { super.paintComponent(g); myIcon.paintIcon(this, g, 0, 0); }
Great library!
ReplyDeleteI've noticed that dev.off() will RCaller will produce parse error:
Parse error at line 1, column 6. Encountered: device
at bsh.Parser.generateParseException(Unknown Source)
at bsh.Parser.jj_consume_token(Unknown Source)
at bsh.Parser.Statement(Unknown Source)
at bsh.Parser.BlockStatement(Unknown Source)
at bsh.Parser.Line(Unknown Source)
at bsh.Interpreter.Line(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at rcaller.StreamReader.run(RCaller.java:79)
My solution was to just leave it out, but this could be a problem in some situation.
Is the error message from dev.off() common?
this method of plotting is deprecated in version 2.0.
ReplyDeletePlease use the internal plotting functionality of RCaller 2.0 instead this way.
i want to call rscript from java but not able to load...
ReplyDeleteRCaller caller=new RCaller();
caller.setRScriptExecutableFile("C:\\Program Files\\R1.4...\\R\\Rscript\\Rscript.exe");
"setRScriptExecutableFile" itself gives the error...
can anyone help in this ??
which version of RCaller are you using and what is the error throwed?
ReplyDeleteusing rcaller: 2.0
ReplyDeletecode is workign on eclipse 9.0
yestarday was not workign on eclipse 3.6 or i might be doing somethign wrong,code i am usin is:
RCaller caller = new RCaller();
//caller.setRscriptExecutable("/usr/bin/Rscript");
caller.setRscriptExecutable("C:\\local\\R\\R-2.13.1\\bin\\Rscript.exe");
caller.cleanRCode();
double[] numbers = new double[] {1,4,3,5,6,10};
// Graph
caller.addDoubleArray("x", numbers);
File file = caller.startPlot();
System.out.println(file);
caller.addRCode("plot.ts(x)");
caller.endPlot();
caller.runOnly();
caller.showPlot(file);
ok. what is the error?
ReplyDeletewill run on eclipse 3.6 in eve again once i am at home.. will post the error..
ReplyDeleteHi can you elaborate with example code... I am facing the same problem
ReplyDeleteMy code snip goes like this:
code.addRCode("png(filename = \"c:/h31.png\",width = 700, height = 700, units = \"px\", pointsize = 12,bg = \"white\", res = NA, family = \"\", restoreConsole = TRUE,type = c(\"windows\", \"cairo\", \"cairo-png\"))");
code.addRCode("prot_heatmap <- heatmap(prot_matrix, scale=\"column\", margins=c(3,3))");
code.addRCode("dev.off()");
This returns an empty string
Hi, I am generating a plot using RCaller. I am clicking on a button from class A_JFrame. This button call B_JCaller class and open plot in a new window. when I close plot window, parent window also getting close. Parent window should not be close. If any solution, kindly share.
ReplyDelete