Package com.twosigma.beaker.jvm.object

Examples of com.twosigma.beaker.jvm.object.SimpleEvaluationObject


  @POST
  @Path("evaluate")
  public SimpleEvaluationObject evaluate(@FormParam("shellId") String shellId,
      @FormParam("code") String code) throws InterruptedException {

    SimpleEvaluationObject obj = new SimpleEvaluationObject(code);
    obj.started();
    if(!this.shells.containsKey(shellId)) {
      obj.error("Cannot find shell");
        return obj;
    }
    try {
        this.shells.get(shellId).evaluate(obj, code);
    } catch (Exception e) {
      obj.error(e.toString());
        return obj;
    }
    return obj;
  }
View Full Code Here


  @Path("evaluate")
  public SimpleEvaluationObject evaluate(
      @FormParam("shellId") String shellId,
      @FormParam("code") String code) throws InterruptedException {

    SimpleEvaluationObject obj = new SimpleEvaluationObject(code);
    obj.started();
    if(!this.shells.containsKey(shellId)) {
      obj.error("Cannot find shell");
      return obj;
    }
    try {
      this.shells.get(shellId).evaluate(obj, code);
    } catch (Exception e) {
      obj.error(e.toString());
      return obj;
    }
    return obj;
  }
View Full Code Here

      @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;
View Full Code Here

TOP

Related Classes of com.twosigma.beaker.jvm.object.SimpleEvaluationObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.