Search in sources :

Example 1 with AbstractAtomicVector

use of org.renjin.sexp.AbstractAtomicVector in project bamboobsc by billchen198318.

the class ScriptExpressionUtils method executeRenjin.

private static void executeRenjin(String scriptExpression, Map<String, Object> results, Map<String, Object> parameters) throws Exception {
    ScriptEngine engine = buildRenjinScriptEngine();
    if (parameters != null) {
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            engine.put(entry.getKey(), entry.getValue());
        }
    }
    engine.eval(scriptExpression);
    if (results != null) {
        for (Map.Entry<String, Object> entry : results.entrySet()) {
            Object res = engine.get(entry.getKey());
            if (res instanceof AbstractAtomicVector) {
                if (((AbstractAtomicVector) res).length() > 0) {
                    entry.setValue(((AbstractAtomicVector) res).getElementAsObject(0));
                }
            } else {
                entry.setValue(res);
            }
        }
    }
}
Also used : AbstractAtomicVector(org.renjin.sexp.AbstractAtomicVector) PyObject(org.python.core.PyObject) Map(java.util.Map) ScriptEngine(javax.script.ScriptEngine)

Aggregations

Map (java.util.Map)1 ScriptEngine (javax.script.ScriptEngine)1 PyObject (org.python.core.PyObject)1 AbstractAtomicVector (org.renjin.sexp.AbstractAtomicVector)1