I have simple java program which reads data from csv file and validate the data then call the R script to calculate the average of list of values, i'm using Renjin to call R program. I am able to call R script without passing parameter but here i need to pass list of values to my R script.
Here is my java code:
// listofval --list of float values example listofval= [3.3,5.2,6,9]
RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
engine.put("input",listofval);
engine.eval(new java.io.FileReader("avg.R"));
Here is my Rscript:
args=(commandArgs(TRUE))
args <- eval(parse(text=args[1]))
input <- args
customMean <- function(vector) {
mean(vector)
}
result.mean<- customMean(input)
print(result.mean)
I'm looking for work around, Can someone please help me on this?
Thanks in advance.