Package org.rosuda.REngine

Examples of org.rosuda.REngine.REXP


        throw new RemoteException("Unable to run computation on two arrays with different lengths (" + columnLength
          + " != " + inputValues[j].length + ").");
       
      }
     
      REXP evalValue; 
      String names = "";
     
//      We have to send columns to R and receive them back to be sent once again to R
      //enables 'n' number of columns to be sent
      for (int i = 0; i < inputNames.length; i++)
      {
        String name = inputNames[i];
        if(names.length() != 0){
          names = names + "," + name;}
        else{
          names = name;
        }
        double[] value = ListUtils.copyDoubleArray(inputValues[i], new double[inputValues[i].length]);
        rConnection.assign(name, value)
   
      }
      evalValue = rConnection.eval("data.frame(" + names + ")"); // NOT SAFE - script was built using user-specified strings
   
      rConnection.assign("frame",evalValue);
      rConnection.assign("clusternumber", noOfClusters);
      rConnection.assign("iterations",iterationNumber);

     
      //String script = "Clus <- kmeans(frame, "+numberOfClusters+","+iterations+")";
     
//    String clusteringScript = "Clustering <- function(dframe, clusternumber, iterations)\n" +
//                    "{result1 <- kmeans(dframe, clusternumber, iterations)\n " +
//                    "result2 <- kmeans(dframe, clusternumber, (iterations - 1))\n " +
//                    "while(result1$totss != result2$totss)\n"+
//                    "{iterations <- iterations + 1 \n " +
//                    "result1 <- kmeans(dframe, clusternumber, iterations)\n " +
//                    "result2 <- kmeans(dframe, clusternumber, (iterations - 1))\n }" +
//                    "print(result1)" +
//                    "print(result2)" +
//                    "}" +
//                    "KCluResult <- Clustering(frame,clusternumber, iterations)";
 
      String clusteringScript = "KClusResult <- kmeans(frame, clusternumber,iterations)";
     
      int i = 0;
      String[] outputNames = {"KClusResult$cluster", "KClusResult$centers"};
      evalScript(rConnection, clusteringScript, showWarnings);
     
      int iterationTimes = outputNames.length;
   
      kClusteringResult = new RResult[outputNames.length];
      for (; i < iterationTimes; i++)
      {
        String name;
        // Boolean addedTolist = false;
        if (iterationTimes == outputNames.length + 1){
          name = outputNames[i - 1];
        }
        else{
          name = outputNames[i];
        }
        // Script to get R - output
        evalValue = evalScript(rConnection, name, showWarnings);       
//        System.out.println(evalValue);
        if (evalValue.isVector()){
          if (evalValue instanceof REXPString)
            kClusteringResult[i] = new RResult(name, evalValue.asStrings());
          else if (evalValue instanceof REXPInteger)
            kClusteringResult[i] = new RResult(name, evalValue.asIntegers());
          else if (evalValue instanceof REXPDouble){
            if (evalValue.dim() == null)
              kClusteringResult[i] = new RResult(name, evalValue.asDoubles());
            else
              kClusteringResult[i] = new RResult(name, evalValue.asDoubleMatrix());
          }
          else{
            // if no previous cases were true, return debug String
            kClusteringResult[i] = new RResult(name, evalValue.toDebugString());
          }
        }
        else{
          kClusteringResult[i] = new RResult(name, evalValue.toDebugString());
        }
      }
    }
    catch (Exception e)
    {
View Full Code Here


    {
      rConnection = getRConnection()
      requestScriptAccess(rConnection); // doing this because the eval() call below is not safe
     
      String script= "";
      REXP evalValue;
      String names = "";
     
//      We have to send columns to R and receive them back to be sent once again to R
      for (int i = 0; i < inputNames.length; i++)
      {
        String name = inputNames[i];
        if(names.length() != 0){
          names = names + "," + name;}
        else{
          names = name;
        }
        double[] value = ListUtils.copyDoubleArray(inputValues[i], new double[inputValues[i].length]);
        rConnection.assign(name, value)
      }
     
      evalValue = rConnection.eval("Bind <- cbind(" + names + ")"); // NOT SAFE - bindingInput was built with string concat using user-specified strings
     
      //Built in script
      if(completeProcess = false)
      {
        script = "library(norm) \n pre <- prelim.norm(Bind)";
       
      }
      else
      {
        script = "library(norm) \n pre <- prelim.norm(Bind) \n eeo <- em.norm(pre) \n rngseed(12345) \n" +
        "imputed <- imp.norm(pre, eeo,Bind)";
      }
     
     
         
      evalScript(rConnection, script, showWarnings);
   
      int i = 0;
      int iterationTimes = outputNames.length;
   
      mdResult = new RResult[outputNames.length];
      for (; i < iterationTimes; i++)
      {
        String name;
        // Boolean addedTolist = false;
        if (iterationTimes == outputNames.length + 1){
          name = outputNames[i - 1];
        }
        else{
          name = outputNames[i];
        }
        // Script to get R - output
        evalValue = evalScript(rConnection, name, showWarnings);       
//        System.out.println(evalValue);
        if (evalValue.isVector()){
          if (evalValue instanceof REXPString)
            mdResult[i] = new RResult(name, evalValue.asStrings());
          else if (evalValue instanceof REXPInteger)
            mdResult[i] = new RResult(name, evalValue.asIntegers());
          else if (evalValue instanceof REXPDouble){
            if (evalValue.dim() == null)
              mdResult[i] = new RResult(name, evalValue.asDoubles());
            else
              mdResult[i] = new RResult(name, evalValue.asDoubleMatrix());
          }
          else{
            // if no previous cases were true, return debug String
            mdResult[i] = new RResult(name, evalValue.toDebugString());
          }
        }
        else{
          mdResult[i] = new RResult(name, evalValue.toDebugString());
        }
      }
    }
    catch (Exception e)
    {
View Full Code Here

          assignArg(entry.getKey(), entry.getValue());
        }
      }
    }
    try {
      REXP rexp = myEval(script);
      return RUtils.rexp2jobj(rexp);
    }
    catch(Exception rme) {
      throw new ScriptException(rme);
    }
View Full Code Here

      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

      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

          if (i < (parameters.length - 1))
            argument.append(",");
        }

        REXP rdata = null;
        try {
          rdata = getConnection().eval(
              function_name + "(" + argument.toString() + "))");
        } catch (Exception e) {
          ByteArrayOutputStream output = new ByteArrayOutputStream();
View Full Code Here

      try {
        RResultAgg myagg = (RResultAgg) agg;
        String function_name = myagg.funcName + ".partial";

        REXP rdata = null;
        try {
          if (myagg.values == null) {
            rdata = getConnection().eval(function_name + "(NULL)");
          } else {
            rdata = getConnection().eval(
View Full Code Here

        try {
          loadRObjects(myagg.funcName);

          String function_name = myagg.funcName + ".merge";

          REXP rdata = null;
          try {
            if (myagg.values == null) {
              rdata = getConnection().eval(
                  function_name + "(NULL," + partial_value
                      + ")");
View Full Code Here

        return null;
      }
      try {
        String function_name = myagg.funcName + ".terminate";

        REXP rdata = null;
        try {
          if (myagg.values == null) {
            rdata = getConnection().eval(function_name + "(NULL)");
          } else {
            rdata = getConnection().eval(
View Full Code Here

        throws HiveException {
      if (!funcSet.contains(export_name)) {

        try {

          REXP rhive_data = getConnection().eval(
              "Sys.getenv('RHIVE_DATA')");
          String srhive_data = null;

          if (rhive_data != null) {
            srhive_data = rhive_data.asString();
          }

          if (srhive_data == null || srhive_data.length() == 0) {
            getConnection().eval(
                "load(file=paste('/tmp','/" + export_name
View Full Code Here

TOP

Related Classes of org.rosuda.REngine.REXP

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.