コード例 #1
0
ファイル: Context.java プロジェクト: fosterac/renjin
 protected void evalBaseResource(String resourceName) throws IOException {
   Context evalContext = this.beginEvalContext(session.getBaseNamespaceEnv());
   InputStream in = getClass().getResourceAsStream(resourceName);
   if (in == null) {
     throw new IOException("Could not load resource '" + resourceName + "'");
   }
   Reader reader = new InputStreamReader(in);
   try {
     evalContext.evaluate(RParser.parseSource(reader));
   } finally {
     reader.close();
   }
 }
コード例 #2
0
ファイル: AetherTest.java プロジェクト: beattyk1/renjin
  private String evaluate(String script) throws IOException {
    AetherPackageLoader aetherLoader = new AetherPackageLoader();
    aetherLoader.setTransferListener(new ConsoleTransferListener());
    aetherLoader.setRepositoryListener(new ConsoleRepositoryListener(System.out));

    Session session =
        new SessionBuilder()
            .bind(ClassLoader.class, aetherLoader.getClassLoader())
            .bind(PackageLoader.class, aetherLoader)
            .build();

    ExpressionVector sexp = RParser.parseAllSource(new StringReader(script));

    SEXP result = session.getTopLevelContext().evaluate(sexp);

    if (result instanceof StringVector) {
      return ((StringVector) result).getElementAsString(0);
    } else {
      throw new AssertionError("Expected string, got: " + result);
    }
  }