@FormParam("shellID") String shellID,
@FormParam("init") String initString,
@FormParam("code") String code)
throws InterruptedException, REXPMismatchException, IOException
{
SimpleEvaluationObject obj = new SimpleEvaluationObject(code);
obj.started();
RServer server = getEvaluator(shellID);
RConnection con = server.connection;
boolean init = initString != null && initString.equals("true");
String file = windows() ? "rplot.svg" : makeTemp("rplot", ".svg");
try {
java.nio.file.Path p = java.nio.file.Paths.get(file);
java.nio.file.Files.deleteIfExists(p);
} catch (IOException e) {
// ignore
}
try {
// direct graphical output
String tryCode;
if (init) {
tryCode = code;
} else {
con.eval("do.call(svg,c(list('" + file + "'), beaker::saved_svg_options))");
tryCode = "beaker_eval_=withVisible(try({" + code + "\n},silent=TRUE))";
}
REXP result = con.eval(tryCode);
if (init) {
obj.finished(result.asString());
return obj;
}
if (false) {
if (null != result)
System.out.println("result class = " + result.getClass().getName());
else
System.out.println("result = null");
}
if (null == result) {
obj.finished("");
} else if (isError(result, obj)) {
} else if (!isVisible(result, obj)) {
obj.finished("");
} else if (isDataFrame(result, obj)) {
// nothing
} else {
server.outputHandler.reset(obj);
String finish = "print(\"" + BEGIN_MAGIC + "\")\n" +
"print(beaker_eval_$value)\n" +
"print(\"" + END_MAGIC + "\")\n";
con.eval(finish);
}
} catch (RserveException e) {
if (127 == e.getRequestReturnCode()) {
obj.error("Interrupted");
} else {
obj.error(e.getMessage());
}
}
// flush graphical output
try {
con.eval("dev.off()");
} catch (RserveException e) {
obj.error("from dev.off(): " + e.getMessage());
}
addSvgResults(file, obj);
return obj;