Let's say I have created a function in R like
bin <- function(arg1, arg2, arg3) {
//some code here
}
I am using Renjin to run R on the JVM. From my Java program, I want to call my R function bin
. I know you need to use something similar to this first just to access R
ScriptEngineManager manager = new ScriptEngineManager();
// create a Renjin engine:
ScriptEngine engine = manager.getEngineByName("Renjin");
but once that is done, how exactly do I access my R function? This function is stored in a separate file. I know that to run an R script (let's call this script.R
), you use
engine.eval(new java.io.FileReader("script.R"));
but that doesn't allow argument passing in functions in the file... it just runs the whole thing.
Would I have to just rewrite the function using R/Renjin in my Java program? Or is there an efficient way to call the function?
Thank you!