Package org.rosuda.REngine

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


    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

      }
      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

  }

  /** 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

  }

  /** 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

    return map;   
  }

  /** Convert from R expression to Java array. */
  private static Object asArray(REXP rexp, Class<?> type) throws REXPMismatchException {
    RList rlist = rexp.asList();
    int len = rlist.size();
    Object array = Array.newInstance(type, len);
    for(int i = 0; i < len; ++i) {
      Object val = rexp2jobj(rlist.at(i), type);
      Array.set(array, i, val);
    }
    return array;
  }
View Full Code Here

  /** Convert from R expression to Java RObject. */
  @SuppressWarnings("unused")
  private static Object asRObject(REXP rexp, Class<?> type) {
    try {
      RList rlist = rexp.asList();
      Object obj = type.newInstance();
      if(rlist.isNamed()) {
        for(int i = 0; i < rlist.size(); ++i) {
          String name = rlist.names.get(i).toString();
          Field fld = type.getField(name);
          REXP value = (REXP) rlist.get(i);
          Object val = rexp2jobj(value, fld.getType());
          fld.set(obj, val);
        }
      }
      return obj;
View Full Code Here

      Map<String, PropertyDescriptor> map =
        new HashMap<String, PropertyDescriptor>(props.length * 2);
      for(PropertyDescriptor prop : props) {
        map.put(prop.getName(), prop);
      }
      RList rlist = rexp.asList();
      Object obj = type.newInstance();
      if(rlist.isNamed()) {
        for(int i = 0; i < rlist.size(); ++i) {
          String name = rlist.names.get(i).toString();
          PropertyDescriptor prop = map.get(name);
          Method method = prop.getWriteMethod();
          REXP value = (REXP) rlist.get(i);
          Object val = rexp2jobj(value, prop.getPropertyType());
          method.invoke(obj, val);
        }
      }
      return obj;
View Full Code Here

    for(int i = 0; i < nrow; ++i) {
      for(int j = 0; j < ncol; ++j) {
        ret[j * nrow + i] = mat[i][j];
      }
    }
    RList rlist = new RList();
    rlist.put("dim", new REXPInteger(new int[] { nrow, ncol }));
    REXPList attrs = new REXPList(rlist);
    return new REXPDouble(ret, attrs);
  }
View Full Code Here

    return namevalues2rexp(names, rexps);
  }

  /** Convert name value pairs to R expression. */
  private static REXP namevalues2rexp(String[] names, REXP[] rexps) {
    return new REXPGenericVector(new RList(rexps, names));   
  }
View Full Code Here

TOP

Related Classes of org.rosuda.REngine.RList

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.