Examples of RList


Examples of com.guokr.simbase.command.RList

        registry.add("iadd", new IAdd());
        registry.add("iget", new IGet());
        registry.add("iset", new ISet());
        registry.add("iacc", new IAcc());

        registry.add("rlist", new RList());
        registry.add("rmk", new RMk());
        registry.add("rget", new RGet());
        registry.add("rrec", new RRec());

        registry.add("xacc", new XAcc());
View Full Code Here

Examples of org.rosuda.JRI.RList

        for (Enumeration e = v.getNames().elements() ; e.hasMoreElements() ;) {
          System.out.println(e.nextElement());
        }
      }
      // for compatibility with Rserve we allow casting of vectors to lists
      RList vl = x.asList();
      String[] k = vl.keys();
      if (k!=null) {
        System.out.println("and once again from the list:");
        int i=0; while (i<k.length) System.out.println(k[i++]);
      }     

      // get boolean array
      System.out.println(x=re.eval("iris[[1]]>mean(iris[[1]])"));
      // R knows about TRUE/FALSE/NA, so we cannot use boolean[] this way
      // instead, we use int[] which is more convenient (and what R uses internally anyway)
      int[] bi = x.asIntArray();
      {
          int i = 0; while (i<bi.length) { System.out.print(bi[i]==0?"F ":(bi[i]==1?"T ":"NA ")); i++; }
          System.out.println("");
      }
     
      // push a boolean array
      boolean by[] = { true, false, false };
      re.assign("bool", by);
      System.out.println(x=re.eval("bool"));
      // asBool returns the first element of the array as RBool
      // (mostly useful for boolean arrays of the length 1). is should return true
      System.out.println("isTRUE? "+x.asBool().isTRUE());

      // now for a real dotted-pair list:
      System.out.println(x=re.eval("pairlist(a=1,b='foo',c=1:5)"));
      RList l = x.asList();
      if (l!=null) {
        int i=0;
        String [] a = l.keys();
        System.out.println("Keys:");
        while (i<a.length) System.out.println(a[i++]);
        System.out.println("Contents:");
        i=0;
        while (i<a.length) System.out.println(l.at(i++));
      }
      System.out.println(re.eval("sqrt(36)"));
    } catch (Exception e) {
      System.out.println("EX:"+e);
      e.printStackTrace();
View Full Code Here

Examples of org.rosuda.JRI.RList

        for (Enumeration e = v.getNames().elements() ; e.hasMoreElements() ;) {
          System.out.println(e.nextElement());
        }
      }
      // for compatibility with Rserve we allow casting of vectors to lists
      RList vl = x.asList();
      String[] k = vl.keys();
      if (k!=null) {
        System.out.println("and once again from the list:");
        int i=0; while (i<k.length) System.out.println(k[i++]);
      }     

      // get boolean array
      System.out.println(x=re.eval("iris[[1]]>mean(iris[[1]])"));
      // R knows about TRUE/FALSE/NA, so we cannot use boolean[] this way
      // instead, we use int[] which is more convenient (and what R uses internally anyway)
      int[] bi = x.asIntArray();
      {
          int i = 0; while (i<bi.length) { System.out.print(bi[i]==0?"F ":(bi[i]==1?"T ":"NA ")); i++; }
          System.out.println("");
      }
     
      // push a boolean array
      boolean by[] = { true, false, false };
      re.assign("bool", by);
      System.out.println(x=re.eval("bool"));
      // asBool returns the first element of the array as RBool
      // (mostly useful for boolean arrays of the length 1). is should return true
      System.out.println("isTRUE? "+x.asBool().isTRUE());

      // now for a real dotted-pair list:
      System.out.println(x=re.eval("pairlist(a=1,b='foo',c=1:5)"));
      RList l = x.asList();
      if (l!=null) {
        int i=0;
        String [] a = l.keys();
        System.out.println("Keys:");
        while (i<a.length) System.out.println(a[i++]);
        System.out.println("Contents:");
        i=0;
        while (i<a.length) System.out.println(l.at(i++));
      }
      System.out.println(re.eval("sqrt(36)"));
    } catch (Exception e) {
      System.out.println("EX:"+e);
      e.printStackTrace();
View Full Code Here

Examples of org.rosuda.JRI.RList

        }
        predictedValues.put(name, vectorSubResult);
        break;
       
      case REXP.XT_LIST:
        RList rList = rResult.asList();
        Map<String, Object> listSubResult = new HashMap<String, Object>();
        for(String lName : rList.keys()) {
          processRResult(rList.at(lName), listSubResult, lName);
        }
        predictedValues.put(name, listSubResult);
        break;
      default:
        log.log(Level.WARNING, "Unsopported R expression/result type " + rResult.getType() + ". Will not add it to predicted values");
View Full Code Here

Examples of org.rosuda.JRI.RList

        for (Enumeration e = v.getNames().elements() ; e.hasMoreElements() ;) {
          System.out.println(e.nextElement());
        }
      }
      // for compatibility with Rserve we allow casting of vectors to lists
      RList vl = x.asList();
      String[] k = vl.keys();
      if (k!=null) {
        System.out.println("and once again from the list:");
        int i=0; while (i<k.length) System.out.println(k[i++]);
      }     

      // get boolean array
      System.out.println(x=re.eval("iris[[1]]>mean(iris[[1]])"));
      // R knows about TRUE/FALSE/NA, so we cannot use boolean[] this way
      // instead, we use int[] which is more convenient (and what R uses internally anyway)
      int[] bi = x.asIntArray();
      {
          int i = 0; while (i<bi.length) { System.out.print(bi[i]==0?"F ":(bi[i]==1?"T ":"NA ")); i++; }
          System.out.println("");
      }
     
      // push a boolean array
      boolean by[] = { true, false, false };
      re.assign("bool", by);
      System.out.println(x=re.eval("bool"));
      // asBool returns the first element of the array as RBool
      // (mostly useful for boolean arrays of the length 1). is should return true
      System.out.println("isTRUE? "+x.asBool().isTRUE());

      // now for a real dotted-pair list:
      System.out.println(x=re.eval("pairlist(a=1,b='foo',c=1:5)"));
      RList l = x.asList();
      if (l!=null) {
        int i=0;
        String [] a = l.keys();
        System.out.println("Keys:");
        while (i<a.length) System.out.println(a[i++]);
        System.out.println("Contents:");
        i=0;
        while (i<a.length) System.out.println(l.at(i++));
      }
      System.out.println(re.eval("sqrt(36)"));
    } catch (Exception e) {
      System.out.println("EX:"+e);
      e.printStackTrace();
View Full Code Here

Examples of org.rosuda.REngine.RList

  }

  private static boolean isDataFrame(REXP result, SimpleEvaluationObject obj) {
    TableDisplay table;
    try {
      RList list = result.asList().at(0).asList();
      int cols = list.size();
      String[] names = list.keys();
      if (null == names) {
        return false;
      }
      String[][] array = new String[cols][];
      List<List> values = new ArrayList<>();
      List<Class> classes = new ArrayList<>();

      for (int i = 0; i < cols; i++) {
        // XXX should identify numeric columns
        classes.add(String.class);
        if (null == list.at(i)) {
          return false;
        }
        array[i] = list.at(i).asStrings();
      }
      if (array.length < 1) {
        return false;
      }
      for (int j = 0; j < array[0].length; j++) {
View Full Code Here

Examples of org.rosuda.REngine.RList

    if (object instanceof Object[])
    {
      Object[] array = (Object[])object;
      if (array.length == 0)
      {
        return new REXPList(new RList());
      }
      else if (array[0] instanceof String)
      {
        String[] strings = ListUtils.copyStringArray(array, new String[array.length]);
        return new REXPString(strings);
      }
      else if (array[0] instanceof Number)
      {
        double[] doubles = ListUtils.copyDoubleArray(array, new double[array.length]);
        return new REXPDouble(doubles);
      }
      else if (array[0] instanceof Object[]) // 2-d matrix
      {
        // handle 2-d matrix
        RList rList = new RList();
        for (Object item : array)
          rList.add(getREXP(item));

        try {
          return REXP.createDataFrame(rList);
        } catch (REXPMismatchException e) {
          throw new RemoteException("Failed to Create Dataframe",e);
View Full Code Here

Examples of org.rosuda.REngine.RList

      }
      if(rexp.isRaw()) {
        return rexp.asBytes();
      }
      if(rexp.isList()) {
        RList rList = rexp.asList();
        Object[] listOfREXP = rList.toArray();
        //convert object in List as Java Objects
        // eg: REXPDouble as Double or Doubles
        for(int i = 0; i < listOfREXP.length; i++){
          REXP obj = (REXP)listOfREXP[i];
          Object javaObj =  rexp2javaObj(obj);
View Full Code Here

Examples of org.rosuda.REngine.RList

  }

  /** Convert from R expression to Java List. */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  private static List asList(REXP rexp) throws REXPMismatchException {
    RList rlist = rexp.asList();
    List list = new ArrayList(rlist.size());
    for(Object o : rlist) {
      list.add(rexp2jobj((REXP)o));
    }
    return list;   
  }
View Full Code Here

Examples of org.rosuda.REngine.RList

  }

  /** Convert from R expression to Java Map. */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  private static Map asMap(REXP rexp) throws REXPMismatchException {
    RList rlist = rexp.asList();
    int len = rlist.size();
    Map map = new HashMap<String, Object>(len);
    if(rlist.isNamed()) {
      System.out.println("isNamed");
      for(int i = 0; i < len; ++i) {
        System.out.println(String.format("%s: %s",rlist.names.get(i), rexp2jobj(rlist.at(i))));
        map.put(rlist.names.get(i), rexp2jobj(rlist.at(i)));
      }
    }
    System.out.println(map);
    return map;   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.