Package org.rosuda.REngine

Examples of org.rosuda.REngine.REXP


        tryCode = code;
      } else {
        con.eval("do.call(svg,c(list('" + file + "'), beaker::saved_svg_options))");
        tryCode = "beaker_eval_=withVisible(try({" + code + "\n},silent=TRUE))";
      }
      REXP result = con.eval(tryCode);
      if (init) {
        obj.finished(result.asString());
        return obj;
      }

      if (false) {
        if (null != result)
          System.out.println("result class = " + result.getClass().getName());
        else
          System.out.println("result = null");
      }

      if (null == result) {
View Full Code Here


    return false;
  }

  private static boolean isError(REXP result, SimpleEvaluationObject obj) {
    try {
      REXP value = result.asList().at(0);
      if (value.inherits("try-error")) {
        String prefix = "Error in try({ : ";
        String rs = value.asString();
        if (rs.substring(0, prefix.length()).equals(prefix)) {
          rs = rs.substring(prefix.length());
        }
        obj.error(rs);
        return true;
View Full Code Here

      {
        Logs.log("Couldn't evaluate R command because either couldn't start server or connect to server!", 0, "R");
        return null;
      }
    }
    REXP ret = null;
    try
    {
      if(!safe && asString)
      {
        ret = rConnection.eval("paste(capture.output(print(" + command + ")),collapse='\\n')");
        Logs.log(ret.asString(), R.class);
      }
      else if(!safe)
      {
        ret = rConnection.parseAndEval("try(" + command + ",silent=TRUE)");
        if(ret.inherits("try-error"))
        {
          Logs.log(ret.asString(), Logs.ERROR, R.class);
        }
        else
        {}
      }
      else //safe
View Full Code Here

    return false;
  }
 
  public REXP get(String name)
  {
    REXP ret = null;
    try
    {
      R.rConnection.get(name, ret, true);
    }
    catch (REngineException e)
View Full Code Here

      return;
   
    try
    {
      rConnection.assign(".tmp.", WeaveConfig.getConnectionConfigFilePath());
      REXP result = rConnection.eval("length(readLines(.tmp.))");
      rConnection.assign(".tmp.", new REXPNull());
      rConnection.close(); // must close before throwing exception
      if (result.isNumeric())
        throw new RemoteException("R script access is not allowed because it is unsafe (The user running Rserve has file read/write access).");
      throw new RemoteException("Unexpected result in requestScriptAccess(): " + result);
    }
    catch (RserveException e)
    {
View Full Code Here

  }
 
  private static REXP evalScript(RConnection rConnection, String script, boolean showWarnings) throws REXPMismatchException,RserveException
  {
    int warn = showWarnings ? 2 : 1;
    REXP evalValue = rConnection.eval("try({ options(warn=" + warn + ") \n" + script + "},silent=TRUE)");
    return evalValue;
  }
View Full Code Here

        for (int i = 0; i < Rdatas.length; i++)
        {
          String scriptToAcessRObj = Rdatas[i];
          if (scriptToAcessRObj.compareTo("mycache") == 0)
            continue;
          REXP RobjValue = evalScript(rConnection, scriptToAcessRObj, false);
          //When function reference is called returns null
          if (RobjValue == null)
            continue;
          resultVector.add(new RResult(scriptToAcessRObj, rexp2javaObj(RobjValue)))
        }
View Full Code Here

        String plotEvalValue = plotEvalScript(rConnection,docrootPath, plotScript, showWarnings);
        resultVector.add(new RResult("Plot Results", plotEvalValue));
      }
      for (int i = 0; i < outputNames.length; i++){// R Script to EVALUATE output Script
        String name = outputNames[i];           
        REXP evalValue = evalScript(rConnection, name, showWarnings)
        resultVector.add(new RResult(name, rexp2javaObj(evalValue)));         
      }
      // clear R objects
      evalScript(rConnection, "rm(list=ls())", false);
     
View Full Code Here

        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);
          if (javaObj instanceof RFactor)
          {
            RFactor factorjavaObj = (RFactor)javaObj;
            String[] levels = factorjavaObj.asStrings();
View Full Code Here

     
      String script = "normalized <- t(as.matrix(sapply(data, function(x) {(x - min(x, na.rm=TRUE))/(max(x, na.rm=TRUE)- min(x, na.rm=TRUE))})))";
     
      rConnection.eval(script);
     
      REXP evalValue = rConnection.eval("normalized");
      result = evalValue.asDoubleMatrix();
    }

    catch (Exception e)
    {
      e.printStackTrace();
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.