Package org.renjin.sexp

Examples of org.renjin.sexp.SEXP


    session.setStdOut(printWriter);
    session.setStdErr(printWriter);
  }

  public EvalResult evaluate(SEXP expression) {
    SEXP exp = session.getTopLevelContext().evaluate(expression);
    return new EvalResult(exp, session.isInvisible());
  }
View Full Code Here


      try {
       
        parser.parse();
       
        SEXP exp = parser.getResult();
        if(exp == null) {
          continue;
        }
       
        // clean up last warnings from any previous run
        clearWarnings();
       
        SEXP result = topLevelContext.evaluate(exp, global);

        if(!topLevelContext.getSession().isInvisible()) {
          topLevelContext.evaluate(FunctionCall.newCall(Symbol.get("print"), result))
        }
       
View Full Code Here

      }
    }
  }

  private void printWarnings() {
    SEXP warnings = topLevelContext.getEnvironment().getBaseEnvironment().getVariable(Warning.LAST_WARNING);
    if(warnings != Symbol.UNBOUND_VALUE) {
      topLevelContext.evaluate( FunctionCall.newCall(Symbol.get("print.warnings"), warnings),
        topLevelContext.getEnvironment().getBaseEnvironment());
    }
  }
View Full Code Here

  public void cleanUpGlobalEnvironment() {
    engine.getSession().getGlobalEnvironment().clear();
  }

  protected final void assertIdentical(String x, String y) {
    SEXP xexp;
    try {
      xexp = (SEXP)engine.eval(x);
    } catch (ScriptException e) {
      throw new RuntimeException("Error evaluating: " + x, e);
    }

    SEXP yexp = null;
    try {
      yexp = (SEXP)engine.eval(y);
    } catch (ScriptException e) {
      throw new RuntimeException("Error evaluating: " + y, e);
    }
View Full Code Here

  public static GraphicsDevice GEcurrentDevice(@Current Context context) {
    /* If there are no active devices
     * check the options for a "default device".
     * If there is one, start it up. */
    if (context.getSession().getSingleton(GraphicsDevices.class).isEmpty()) {
      SEXP defdev = context.getSession().getSingleton(Options.class).get("device");
      if (isString(defdev) && length(defdev) > 0) {
        SEXP devName = install(CHAR(STRING_ELT(defdev, 0)));
        /*  Not clear where this should be evaluated, since
            grDevices need not be in the search path.
            So we look for it first on the global search path.
        */
        defdev = findVar(devName, context.getGlobalEnvironment());
        if(defdev != R_UnboundValue) {
          PROTECT(defdev = lang1(devName));
          eval(defdev, context, context.getGlobalEnvironment());
          UNPROTECT(1);
        } else {
          /* Not globally visible:
             try grDevices namespace if loaded.
             The option is unlikely to be set if it is not loaded,
             as the default setting is in grDevices:::.onLoad.
          */
          SEXP ns = context.getSession().getNamespaceRegistry().getNamespace("grDevices").getNamespaceEnvironment();
          if(ns != R_UnboundValue &&
                  findVar(devName, ns) != R_UnboundValue) {
            PROTECT(defdev = lang1(devName));
            eval(defdev, context, ns);
            UNPROTECT(1);
View Full Code Here

    map.put("warnings.length", new IntArrayVector(1000));
    map.put("OutDec", new StringArrayVector("."));
  }

  public SEXP get(String name) {
    SEXP value = map.get(name);
    return value == null ? Null.INSTANCE : value;
  }
View Full Code Here

    SEXP value = map.get(name);
    return value == null ? Null.INSTANCE : value;
  }
 
  public int getInt(String name, int defaultValue) {
    SEXP value = get(name);
    if(value instanceof AtomicVector && value.length() >= 1) {
      return ((AtomicVector)value).getElementAsInt(0);
    }
    return defaultValue;
  }
View Full Code Here

    }
    return defaultValue;
  }

  public SEXP set(String name, SEXP value) {
    SEXP old = map.put(name, value);
    return old == null ? Null.INSTANCE : value;
  }
View Full Code Here

  public void setEnabled(boolean enabled) {
    this.enabled = enabled;
  }
 
  public SEXP getExtends(String className) {
    SEXP value = extendsTable.get(className);
    if(value == null) {
      return Null.INSTANCE;
    } else {
      return value;
    }
View Full Code Here

      throw new UnsupportedOperationException();
    }
  }
 
  public SEXP R_dispatchGeneric(Context context, Symbol fname, Environment ev, SEXP fdef)   {
    SEXP method;
    SEXP f;
    SEXP val=Null.INSTANCE;
    // char *buf, *bufptr;
    int   lwidth = 0;
    boolean prim_case = false;

    Environment f_env;
    if(fdef instanceof Closure) {
      f_env = ((Closure) fdef).getEnclosingEnvironment();
    } else if(fdef instanceof PrimitiveFunction) {
      fdef = R_primitive_generic(fdef);
      if(!(fdef instanceof Closure)) {
        throw new EvalException("Failed to get the generic for the primitive \"%s\"", fname.asString());
      }
      f_env = ((Closure) fdef).getEnclosingEnvironment();
      prim_case = true;       
    } else {
      throw new EvalException("Expected a generic function or a primitive for dispatch, " +
          "got an object of class \"%s\"", fdef.getImplicitClass());
    }
    SEXP mtable = f_env.getVariable(R_allmtable);
    if(mtable == Symbol.UNBOUND_VALUE) {
      do_mtable(fdef, ev); /* Should initialize the generic */       
      mtable = f_env.getVariable(R_allmtable);
    }
    SEXP sigargs = f_env.getVariable(R_sigargs);
    SEXP siglength = f_env.getVariable(R_siglength);

    if(sigargs == Symbol.UNBOUND_VALUE || siglength == Symbol.UNBOUND_VALUE ||
        mtable == Symbol.UNBOUND_VALUE) {       
      throw new EvalException("Generic \"%s\" seems not to have been initialized for table dispatch---need to have .SigArgs and .AllMtable assigned in its environment",
          fname.asString());
    }
    int nargs =  (int)siglength.asReal();
    ListVector.Builder classListBuilder = ListVector.newBuilder();
    StringVector thisClass;
    StringBuilder buf = new StringBuilder();
   
    for(int i = 0; i < nargs; i++) {
      Symbol arg_sym = sigargs.getElementAsSEXP(i);
      if(is_missing_arg(context, arg_sym, ev)) {
        thisClass = s_missing;
      } else {
        /*  get its class */
        SEXP arg;
        try {
          arg = context.evaluate(arg_sym, ev);
        } catch(EvalException e) {
          throw new EvalException(String.format("error in evaluating the argument '%s' in selecting a " +
              "method for function '%s'",
View Full Code Here

TOP

Related Classes of org.renjin.sexp.SEXP

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.