|
You can get RObject using R facade predefined object in JavaScript. Each RObject object provides the set of methods:
Example: r.newSession();
Example: r.saveSession("e;mySession"e;);
Example: r.openSession("e;mySession"e;);
Example: r.voidEval("e;a <- 10"e;); //create variable in R context with integer value
Example: var d = rObject.eval("e;rnorm(2)"e;); //return array of double
Example: rObject.assignObject("e;a"e;, [1,2,3]); //add array variable "e;a"e; to R environment
Example: rObject.help("e;data"e;); //display Data Sets help page from R
Complete example Here is a complete JavaScript example of R session in BioUML.
var rObject = R.connect("e;server.biouml.org"e;, 80); //get remote RObject print(rObject); //print rObject to check R availability rObject.newSession(); //clean R context rObject.voidEval("e;x=0;for(i in 1:100) {x = x+i;}); //execute set of commands var x = rObject.eval("e;x"e;); //get x value from R print(x); //print the result to console rObject.saveSession("e;testSession"e;); //save current variables state
To use x variable value next time you can use script like this:
var rObject = R.connect("e;server.biouml.org"e;, 80); //get remote RObject rObject.openSession("e;testSession"e;); //load saved R session var x = rObject.eval("e;x"e;); //get variable from R print(x); //print x value to console |