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(); } }
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); } }