//this function does not take in a script from the as3 side for imputation, but the script is built in
public static RResult[] handlingMissingData(String[] inputNames, Object[][] inputValues, String[] outputNames, boolean showIntermediateResults, boolean showWarnings, boolean completeProcess) throws RemoteException
{
RConnection rConnection = null;
RResult[] mdResult = null;
try
{
rConnection = getRConnection();
requestScriptAccess(rConnection); // doing this because the eval() call below is not safe
String script= "";
REXP evalValue;
String names = "";
// We have to send columns to R and receive them back to be sent once again to R
for (int i = 0; i < inputNames.length; i++)
{
String name = inputNames[i];
if(names.length() != 0){
names = names + "," + name;}
else{
names = name;
}
double[] value = ListUtils.copyDoubleArray(inputValues[i], new double[inputValues[i].length]);
rConnection.assign(name, value);
}
evalValue = rConnection.eval("Bind <- cbind(" + names + ")"); // NOT SAFE - bindingInput was built with string concat using user-specified strings
//Built in script
if(completeProcess = false)
{
script = "library(norm) \n pre <- prelim.norm(Bind)";
}
else
{
script = "library(norm) \n pre <- prelim.norm(Bind) \n eeo <- em.norm(pre) \n rngseed(12345) \n" +
"imputed <- imp.norm(pre, eeo,Bind)";
}
evalScript(rConnection, script, showWarnings);
int i = 0;
int iterationTimes = outputNames.length;
mdResult = new RResult[outputNames.length];
for (; i < iterationTimes; i++)
{
String name;
// Boolean addedTolist = false;
if (iterationTimes == outputNames.length + 1){
name = outputNames[i - 1];
}
else{
name = outputNames[i];
}
// Script to get R - output
evalValue = evalScript(rConnection, name, showWarnings);
// System.out.println(evalValue);
if (evalValue.isVector()){
if (evalValue instanceof REXPString)
mdResult[i] = new RResult(name, evalValue.asStrings());
else if (evalValue instanceof REXPInteger)
mdResult[i] = new RResult(name, evalValue.asIntegers());
else if (evalValue instanceof REXPDouble){
if (evalValue.dim() == null)
mdResult[i] = new RResult(name, evalValue.asDoubles());
else
mdResult[i] = new RResult(name, evalValue.asDoubleMatrix());
}
else{
// if no previous cases were true, return debug String
mdResult[i] = new RResult(name, evalValue.toDebugString());
}
}
else{
mdResult[i] = new RResult(name, evalValue.toDebugString());
}
}
}
catch (Exception e)
{
e.printStackTrace();
throw new RemoteException("Unable to run R imputation script", e);
}
finally
{
if (rConnection != null)
rConnection.close();
}
return mdResult;
}