Package org.renjin.eval

Examples of org.renjin.eval.EvalException


      tmp = new double[1];
      intW info = new intW(0);
      lapack.dgeev(jobVL, jobVR, n, xvals, n, wR, wI, left, n, right, n, tmp, lwork, info);

      if (info.val != 0)
          throw new EvalException("error code %d from Lapack routine '%s'", info, "dgeev");
     
      lwork = (int) tmp[0];
      work =  new double[lwork];
      lapack.dgeev(jobVL, jobVR, n, xvals, n, wR, wI, left, n, right, n, work, lwork, info);

      if (info.val != 0)
          throw new EvalException("error code %d from Lapack routine '%s'", info, "dgeev");

      ListVector.NamedBuilder ret = new ListVector.NamedBuilder();
     
      if (thereAreComplexResults(n, wR, wI)) {
       
View Full Code Here


  }

  private static int getSquareMatrixSize(SEXP x) {
    Vector xdims =  (Vector)x.getAttribute(Symbols.DIM);
    if(xdims.length() != 2 || xdims.getElementAsInt(0) != xdims.getElementAsInt(1)) {
      throw new EvalException("'x' must be a square numeric matrix");
    }
    int n = xdims.getElementAsInt(0);
    return n;
 
View Full Code Here

  protected SEXP doEval(Context context) {
    try {
      RDataReader reader = new RDataReader(context, resourceProvider.apply(name + ".RData"));
      return reader.readFile();
    } catch (IOException e) {
      throw new EvalException(e);
    }
  }
View Full Code Here

      RDataReader reader = new RDataReader(context,
        new GZIPInputStream(
          new ByteArrayInputStream(bytes)));
      return reader.readFile();
    } catch (IOException e) {
      throw new EvalException(e);
    }
  }
View Full Code Here

    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'",
              arg_sym.getPrintName(), fname.asString()), e);
        }
        thisClass = Methods.R_data_class(arg, true);
      }
      classListBuilder.set(i, thisClass);
      if(i > 0) {
        buf.append("#");
      }
      buf.append(thisClass.asString());
    }
    ListVector classes = classListBuilder.build();
    method = ((Environment)mtable).getVariable(buf.toString());
    if(method == Symbol.UNBOUND_VALUE) {
      method = do_inherited_table(context, classes, fdef, mtable, (Environment)ev);
    }
    /* the rest of this is identical to R_standardGeneric;
         hence the f=method to remind us  */
    f = method;
    if(f.isObject())
      f = R_loadMethod(context, f, fname.getPrintName(), ev);

    if(f instanceof Closure) {
      val = R_execMethod(context, (Closure)f, ev);
    } else if(f instanceof PrimitiveFunction) {
      /* primitives  can't be methods; they arise only as the
      default method when a primitive is made generic.  In this
      case, return a special marker telling the C code to go on
      with the internal computations. */
      //val = R_deferred_default_method();
      throw new UnsupportedOperationException();
    } else {
      throw new EvalException("invalid object (non-function) used as method");

    }
    return val; 
  }
View Full Code Here

    } else if(fdef instanceof PrimitiveFunction ) {
      f_env = context.getBaseEnvironment();
      //mlist = R_primitive_methods((PrimitiveFunction)fdef);
      throw new UnsupportedOperationException();
    } else {
      throw new EvalException("invalid generic function object for method selection for function '%s': expected a function or a primitive, got an object of class \"%s\"",
          fsym.getPrintName(), fdef.getAttributes().getClassVector());
    }
    if(mlist instanceof Null || mlist instanceof Closure || mlist instanceof PrimitiveFunction) {
      f = mlist;
    } else {
      //f = do_dispatch(fname, ev, mlist, TRUE, TRUE);
      throw new UnsupportedOperationException();
    }
    if(f == Null.INSTANCE) {
      SEXP value = R_S_MethodsListSelect(context, StringArrayVector.valueOf(fname), ev, mlist, f_env);
      if(value == Null.INSTANCE) {
        throw new EvalException("no direct or inherited method for function '%s' for this call",
            fname);
      }
      mlist = value;
      /* now look again.  This time the necessary method should
       have been inserted in the MethodsList object */
      f = do_dispatch(context, fname, (Environment)ev, mlist, false, true);
    }
    //    /* loadMethod methods */
    if(f.isObject()) {
      f = R_loadMethod(context, f, fsym.getPrintName(), ev);
    }
    if(f instanceof Closure) {
      return R_execMethod(context, (Closure)f, ev)
    } else if(f instanceof PrimitiveFunction) {
      /* primitives  can't be methods; they arise only as the
      default method when a primitive is made generic.  In this
      case, return a special marker telling the C code to go on
      with the internal computations. */
      // val = R_deferred_default_method();
      throw new UnsupportedOperationException();
    } else {
      throw new EvalException("invalid object (non-function) used as method");
    }
    //    return val;
  }
View Full Code Here

    }

    try {
      return context.evaluate(new FunctionCall(s_MethodsListSelect, args.build()), methodsNamespace);
    } catch(EvalException e) {
      throw new EvalException(String.format("S language method selection got an error when called from" +
          " internal dispatch for function '%s'", fname), e);
    }
  }
View Full Code Here

    if(mlist instanceof Function) {
      return mlist;
    }
    arg_slot = Methods.R_do_slot(context, mlist, s_argument);
    if(arg_slot == Null.INSTANCE) {
      throw new EvalException("object of class \"%s\" used as methods list for function '%s' " +
          "( no 'argument' slot)",
          mlist.toString(), fname);
    }
    if(arg_slot instanceof Symbol) {
      arg_sym = (Symbol) arg_slot;
    } else {
      /* shouldn't happen, since argument in class MethodsList has class
       "name" */
      arg_sym = Symbol.get(arg_slot.asString());
    }
    //    if(arg_sym == Symbols.ELLIPSES || DDVAL(arg_sym) > 0)
    //  error(_("(in selecting a method for function '%s') '...' and related variables cannot be used for methods dispatch"),
    //        CHAR(asChar(fname)));
    //    if(TYPEOF(ev) != ENVSXP) {
    //  error(_("(in selecting a method for function '%s') the 'environment' argument for dispatch must be an R environment; got an object of class \"%s\""),
    //      CHAR(asChar(fname)), class_string(ev));
    //  return(R_NilValue); /* -Wall */
    //    }
    /* find the symbol in the frame, but don't use eval, yet, because
       missing arguments are ok & don't require defaults */
    if(evalArgs) {
      if(is_missing_arg(context, arg_sym, (Environment)ev)) {
        klass = "missing";
      } else {
        /*  get its class */
        SEXP arg, class_obj;
        try {
          arg = context.evaluate(arg_sym, (Environment)ev);
        } catch(EvalException e) {
          throw new EvalException(String.format("error in evaluating the argument '%s' in selecting a method for function '%s'",
              arg_sym.getPrintName(), fname), e);
        }

        class_obj = Methods.R_data_class(arg, true);
        klass = class_obj.asString();
      }
    } else {
      /* the arg contains the class as a string */
      SEXP arg; int check_err;
      try {
        arg = context.evaluate(arg_sym, (Environment)ev);
      } catch(Exception e) {
        throw new EvalException(String.format("error in evaluating the argument '%s' in selecting a method for function '%s'",
            arg_sym.getPrintName(), fname));
     
      klass = arg.asString();
    }
    method = R_find_method(mlist, klass, fname);
    if(method == Null.INSTANCE) {
      if(!firstTry) {
        throw new EvalException("no matching method for function '%s' (argument '%s', with class \"%s\")",
            fname, arg_sym.getPrintName(), klass);
      }
    }
    if(value == Symbol.MISSING_ARG) {/* the check put in before calling
        function  MethodListSelect in R */
      throw new EvalException("recursive use of function '%s' in method selection, with no default method",
          fname);
    }
    if(!(method instanceof Function)) {
      /* assumes method is a methods list itself.  */
      /* call do_dispatch recursively.  Note the NULL for fname; this is
View Full Code Here

      //            CHAR(PRINTNAME(symbol)));
      //      missing = R_GetVarLocMISSING(loc);
      //      val = R_GetVarLocValue(loc);

      if(!next.hasTag()) {
        throw new EvalException("closure formal has no tag! op = " + op);
      }
     
      Symbol symbol = next.getTag();
      SEXP val = rho.findVariable(symbol);
      if(val == Symbol.UNBOUND_VALUE) {
        throw new EvalException("could not find symbol \"%s\" in the environment of the generic function", symbol.getPrintName());
      }

      //      SET_FRAME(newrho, CONS(val, FRAME(newrho)));
      //      SET_TAG(FRAME(newrho), symbol);
View Full Code Here

    case INTERNAL:
        break;
    case STANDARD:/* FIXME --- implement  's' and 'e' axis styles ! */
    case EXTENDED:
    default:
        throw new EvalException("axis style \"%c\" unimplemented", style.name());
    }

    if (isLog(axis)) { /* 10^max may have gotten +Inf ; or  10^min has become 0 */
        if((temp = Math.pow(10., min)) == 0.) {/* or < 1.01*DBL_MIN */
            temp = Math.min(min_o, 1.01* Double.MIN_VALUE); /* allow smaller non 0 */
 
View Full Code Here

TOP

Related Classes of org.renjin.eval.EvalException

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.