Package org.renjin.eval

Examples of org.renjin.eval.EvalException


   
    PairList args = call.getArguments();
    Symbol symbol = args.getElementAsSEXP(0);
    SEXP elementsExp = context.evaluate(args.getElementAsSEXP(1), rho);
    if(!(elementsExp instanceof Vector)) {
      throw new EvalException("invalid for() loop sequence");
    }
    Vector elements = (Vector) elementsExp;
    SEXP statement = args.getElementAsSEXP(2);
    for(int i=0; i!=elements.length(); ++i) {
      try {
View Full Code Here


  }


  private static void assertNotNa(double r1) {
    if(DoubleVector.isNaN(r1)) {
      throw new EvalException("NA/NaN argument");
    }
  }
View Full Code Here

    }
  }

  private static void assertScalar(Context context, SEXP exp) {
    if(exp.length() == 0) {
      throw new EvalException("argument of length 0");
    } else if(exp.length() > 1) {
      Warning.invokeWarning(context, "numerical expression has %d elements: only the first used", exp.length());
    }
  }
View Full Code Here

    }
  }

  private static void assertFinite(String name, double to) {
    if(!DoubleVector.isFinite(to)) {
      throw new EvalException("'" + name + "' must be finite");
    }
  }
View Full Code Here

        times--;
      }
      return result.build();
    } else {
      if(timesVector.length() != x.length()) {
        throw new EvalException("Invalid 'times' value: times must be the same length as x");
      }
      Vector.Builder result = x.newBuilderWithInitialCapacity(x.length());
      for(int i=0;i!=x.length();++i) {
        int times = timesVector.getElementAsInt(i);
        while(times > 0) {
View Full Code Here

        throw new UnsupportedOperationException("implement me!");
      }
    } else if(len != Symbol.MISSING_ARG && len != Symbol.MISSING_ARG) {
      double rout = len.asReal();
      if(Double.isNaN(rout) || rout <= -0.5) {
        throw new EvalException("'length.out' must be a non-negative number");
      }
      lout = (int) Math.ceil(rout);
    }

    if(IntVector.isNA(lout)) {
      double rfrom = (from == Symbol.MISSING_ARG) ? 1.0 : from.asReal();
      double rto = (to == Symbol.MISSING_ARG) ? 1.0 : to.asReal();
      double rby = by.asReal();

      if(by == Symbol.MISSING_ARG) {
        return new Range(rfrom, rto).vector();
      } else {
        return sequenceBy(from, to, rfrom, rto, rby);
      }
    } else if (lout == 0) {
      return new IntArrayVector();

    } else if (one) {
      return new Range(1.0, lout).vector();

    } else if (by == Symbol.MISSING_ARG) {
      double rfrom = from.asReal();
      double rto = to.asReal();
      if(to == Symbol.MISSING_ARG) {
        rto = rfrom + lout - 1;
      }
      if(from == Symbol.MISSING_ARG) {
        rfrom = rto - lout + 1;
      }
      return sequenceFromTo(rfrom, rto, lout);

    } else if (to == Symbol.MISSING_ARG) {
      double rfrom = (from == Symbol.MISSING_ARG) ? 1.0 : from.asReal();
      return sequenceFrom(lout, rfrom, by.asReal());

    } else if (from == Symbol.MISSING_ARG) {
      return sequenceTo(lout, to.asReal(), by.asReal());

    } else {
      throw new EvalException("too many arguments");
    }
  }
View Full Code Here

      } else if(index < 0) {
        hasNeg = true;
      }
    }
    if(hasNeg && hasPos) {
      throw new EvalException("only 0's may be mixed with negative subscripts");
    }
    return !hasNeg;
  }
View Full Code Here

  private static SEXP sequenceBy(SEXP from, SEXP to, double rfrom, double rto, double by) {
    double del = rto - rfrom, n, dd;
    int nn;
    if(!DoubleVector.isFinite(rfrom)) {
      throw new EvalException("'from' must be finite");
    }
    assertFinite("to", rto);
    if(del == 0.0 && rto == 0.0) {
      return to;
    }
    n = del/by;
    if(!DoubleVector.isFinite(n)) {
      if(del == 0.0 && by == 0.0) {
        return from;
      } else {
        throw new EvalException("invalid '(to - from)/by' in 'seq'");
      }
    }
    dd = Math.abs(del)/Math.max(Math.abs(rto), Math.abs(rfrom));
    if(dd < 100 * DoubleVector.EPSILON) {
      return from;
    }
    if(n > (double) Integer.MAX_VALUE) {
      throw new EvalException("'by' argument is much too small");
    }
    if(n < -DoubleVector.EPSILON) {
      throw new EvalException("wrong sign in 'by' argument");
    }
    nn = (int)(n + DoubleVector.EPSILON);
    double ra[] = new double[nn+1];
    for(int i = 0; i <= nn; i++) {
      ra[i] = rfrom + (i * by);
 
View Full Code Here

    return "externalptr";
  }

  private MemberBinding getMemberBinding(Symbol name) {
    if(binding == null) {
      throw new EvalException("ExternalPtr is NULL for name "+name.getPrintName());
    }
    return binding.getMemberBinding(name);
  }
View Full Code Here

    } else if(envirSexp instanceof ListVector) {
      substituteContext = new ListContext((ListVector) envirSexp);
    } else if(envirSexp instanceof PairList) {
      substituteContext = new PairListContext((PairList)envirSexp);
    } else {
      throw new EvalException("Cannot substitute using environment of type %s: expected list, pairlist, or environment",
          envirSexp.getTypeName());
    }
    return substitute(exp, substituteContext);
  }
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.