kwoyke 60ef1c8551 JAVA-2116: Split or move libraries-data-2 module (#9716)
* JAVA-2116: Move Java-R Integration to libraries-6 module

* JAVA-2116: Move Guide to JMapper to libraries-data module
2020-07-17 07:16:41 +05:30

37 lines
1.1 KiB
Java

package com.baeldung.r;
import com.github.rcaller.rstuff.RCaller;
import com.github.rcaller.rstuff.RCallerOptions;
import com.github.rcaller.rstuff.RCode;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* RCaller showcase.
*
* @author Donato Rimenti
*/
public class RCallerMean {
/**
* Invokes the customMean R function passing the given values as arguments.
*
* @param values the input to the mean script
* @return the result of the R script
* @throws IOException if any error occurs
* @throws URISyntaxException if any error occurs
*/
public double mean(int[] values) throws IOException, URISyntaxException {
String fileContent = RUtils.getMeanScriptContent();
RCode code = RCode.create();
code.addRCode(fileContent);
code.addIntArray("input", values);
code.addRCode("result <- customMean(input)");
RCaller caller = RCaller.create(code, RCallerOptions.create());
caller.runAndReturnResult("result");
return caller.getParser()
.getAsDoubleArray("result")[0];
}
}