Java and R bridge -
i want run r-script java. have following code, giving null:
try { rcaller caller = new rcaller(); caller.setrscriptexecutable("c:/program files/r/r-3.0.1/bin/x64/rscript.exe"); caller.cleanrcode(); caller.addrcode("k<-1"); //initializing k 1 caller.addrcode("b<-print(k)"); caller.runandreturnresult("b"); //this should output value of b } catch(exception e) { e.printstacktrace(); }
i don't know i'm doing wrong. please out.
i suggest download latest version, 2.1.1. code below works expected (prints 1
) version 2.1.1.
import rcaller.rcaller; import rcaller.rcode; public class rcallerdemo { public static void main(string[] args) { try { rcaller caller = new rcaller(); caller.setrscriptexecutable("/usr/bin/rscript"); caller.cleanrcode(); rcode code = new rcode(); final string st1 = "k<-1"; final string st2 = "b<-print(k)"; code.addrcode(st1); code.addrcode(st2); caller.setrcode(code); //initializing k 1 caller.runandreturnresult("b"); //this should output value of b int b = caller.getparser().getasintarray("b")[0]; system.out.println(b); } catch (exception e) { e.printstacktrace(); } } }
the example based on original rcaller examples.
Comments
Post a Comment