Exemplo n.º 1
0
 @Override
 public IList value(final IScope scope) throws GamaRuntimeException {
   if (isConst && computed) {
     return GamaListFactory.createWithoutCasting(getType().getContentType(), values);
   }
   for (int i = 0; i < elements.length; i++) {
     if (elements[i] == null) {
       computed = false;
       return GamaListFactory.EMPTY_LIST;
     }
     values[i] = elements[i].value(scope);
   }
   computed = true;
   // Important NOT to return the reference to values (but a copy of it).
   return GamaListFactory.createWithoutCasting(getType().getContentType(), values);
 }
Exemplo n.º 2
0
  public void doRFileEvaluate(final IScope scope) {
    final String RFile = getPath();
    try {
      // Call R
      RCaller caller = new RCaller();

      String RPath = GamaPreferences.LIB_R.value(scope).getPath();
      caller.setRscriptExecutable(RPath);
      // caller.setRscriptExecutable("\"" + RPath + "\"");
      // if(java.lang.System.getProperty("os.name").startsWith("Mac"))
      // {
      // caller.setRscriptExecutable(RPath);
      // }

      RCode c = new RCode();
      List<String> R_statements = new ArrayList<String>();

      // tmthai.begin----------------------------------------------------------------------------
      String fullPath = FileUtils.constructAbsoluteFilePath(scope, RFile, true);
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute.RScript:" + RPath);
        GuiUtils.debug("Stats.R_compute.RFile:" + RFile);
        GuiUtils.debug("Stats.R_compute.fullPath:" + fullPath);
      }

      // FileReader fr = new FileReader(RFile);
      FileReader fr = new FileReader(fullPath);
      // tmthai.end----------------------------------------------------------------------------

      BufferedReader br = new BufferedReader(fr);
      String statement;
      while ((statement = br.readLine()) != null) {
        c.addRCode(statement);
        R_statements.add(statement);
        // java.lang.System.out.println(statement);
        if (DEBUG) {
          GuiUtils.debug("Stats.R_compute.statement:" + statement);
        }
      }

      fr.close();
      br.close();
      caller.setRCode(c);

      GamaMap<String, IList> result = GamaMapFactory.create(Types.STRING, Types.LIST);

      String var = computeVariable(R_statements.get(R_statements.size() - 1).toString());
      caller.runAndReturnResult(var);
      for (String name : caller.getParser().getNames()) {
        Object[] results = null;
        results = caller.getParser().getAsStringArray(name);
        // for (int i = 0; i < results.length; i++) {
        // java.lang.System.out.println(results[i]);
        // }
        if (DEBUG) {
          GuiUtils.debug(
              "Stats.R_compute_param.caller.Name: '"
                  + name
                  + "' length: "
                  + results.length
                  + " - Value: "
                  + results.toString());
        }
        result.put(name, GamaListFactory.createWithoutCasting(Types.NO_TYPE, results));
      }
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute.return:" + result.serialize(false));
      }
      // return result;
      setBuffer(result);

    } catch (Exception ex) {

      throw GamaRuntimeException.error("RCallerExecutionException " + ex.getMessage(), scope);
    }
  }