org.rosuda.REngine.Rserve.RserveException Java Examples

The following examples show how to use org.rosuda.REngine.Rserve.RserveException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Rsession.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set R list in R env.
 * 
 * @param varname R list name
 * @param data numeric data in list
 * @param names names of columns
 */
public boolean set(String varname, double[][] data, String... names) {
  RList list = buildRList(data, names);
  log(HEAD_SET + varname + " <- " + toString(list), Level.INFO);
  try {
    synchronized (connection) {
      connection.assign(varname, REXP.createDataFrame(list));
    }
  } catch (REXPMismatchException re) {
    log(HEAD_ERROR + " RList " + list.toString() + " not convertible as dataframe.", Level.ERROR);
    return false;
  } catch (RserveException ex) {
    log(HEAD_EXCEPTION + ex.getMessage() + "\n  set(String varname=" + varname
        + ",double[][] data, String... names)", Level.ERROR);
    return false;
  }
  return true;
}
 
Example #2
Source File: Rsession.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set R list in R env.
 * 
 * @param varname R list name
 * @param data numeric data in list
 * @param names names of columns
 */
public boolean set(String varname, double[][] data, String... names) {
  RList list = buildRList(data, names);
  log(HEAD_SET + varname + " <- " + toString(list), Level.INFO);
  try {
    synchronized (connection) {
      connection.assign(varname, REXP.createDataFrame(list));
    }
  } catch (REXPMismatchException re) {
    log(HEAD_ERROR + " RList " + list.toString() + " not convertible as dataframe.", Level.ERROR);
    return false;
  } catch (RserveException ex) {
    log(HEAD_EXCEPTION + ex.getMessage() + "\n  set(String varname=" + varname
        + ",double[][] data, String... names)", Level.ERROR);
    return false;
  }
  return true;
}
 
Example #3
Source File: AbstractKiekerRTest.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether the SystemProperty is set that states, that Kieker R-related tests
 * should be executed and Check whether a connection to the Rserve server can be established.
 */
@Before
public void preCheckForRSysPropertyAndConnection() {
	final String messageWhenPropertyNotSet = "Skipping " + this.getClass() + " because system property " + PROPERTY_NAME_KIEKER_R_TEST + " not true";
	Assume.assumeTrue(messageWhenPropertyNotSet, this.isTestKiekerRTestsSet());

	try {
		final RConnection rConnection = new RConnection();
		Assume.assumeTrue(rConnection.isConnected());
		rConnection.close();
	} catch (final RserveException e) { // thrown on new RConnection();
		if (this.isTestKiekerRTestsSet()) {
			Assert.fail("You chose to execute KiekerRTests, but no connection to Rserve can be established.");
		}
	}
}
 
Example #4
Source File: Rsession.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * delete R environment file
 * 
 * @param remoteFile filename to delete
 */
public void removeFile(String remoteFile) {
  try {
    synchronized (connection) {
      connection.removeFile(remoteFile);
    }
  } catch (RserveException ex) {
    log(HEAD_EXCEPTION + ex.getMessage() + "\n  removeFile(String remoteFile=" + remoteFile + ")",
        Level.ERROR);
  }
}
 
Example #5
Source File: Rsession.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * delete R environment file
 * 
 * @param remoteFile filename to delete
 */
public void removeFile(String remoteFile) {
  try {
    synchronized (connection) {
      connection.removeFile(remoteFile);
    }
  } catch (RserveException ex) {
    log(HEAD_EXCEPTION + ex.getMessage() + "\n  removeFile(String remoteFile=" + remoteFile + ")",
        Level.ERROR);
  }
}
 
Example #6
Source File: RSessionWrapper.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public void loadPackage(String packageName) throws RSessionWrapperException {

    String loadCode = "library(" + packageName + ", logical.return = TRUE)";

    if (TRY_MODE)
      loadCode = "try(" + loadCode + ", silent=TRUE)";

    String errorMsg = "The \"" + this.callerFeatureName + "\" requires " + "the \"" + packageName
        + "\" R package, which couldn't be loaded - is it installed in R?";

    if (this.rEngineType == REngineType.RSERVE) {

      if (this.session != null && !this.userCanceled) {
        logger.log(logLvl, "Loading package '" + packageName + "'...");
        int loaded = 0;
        try {

          REXP r = ((RConnection) this.rEngine).eval(loadCode);
          if (r.inherits("try-error")) {
            logger.severe("R Error [0]: " + r.asString());
            logger.severe("R eval attempt [0]: " + loadCode);
          }
          loaded = r.asInteger();
          logger.log(logLvl, "Load status: '" + (loaded != 0) + "'.");

        } catch (RserveException | REXPMismatchException e) {
          logger.log(logLvl, "Loaded package KO: '" + e.getMessage() + "'.");
          // Remain silent if eval KO ("server down").
          loaded = Integer.MIN_VALUE;
        }

        // Throw loading failure only if eval OK, but return FALSE
        // (package not loaded).
        // ("server down" case will be handled soon enough).
        if (loaded == 0)
          if (!this.userCanceled)
            throw new RSessionWrapperException(errorMsg);

        logger.log(logLvl, "Loaded package: '" + packageName + "'.");
      }

    } else { // RCaller

      ((RCaller) rEngine).getRCode().addRCode(loadCode);
      // try {
      //
      // ((RCallerScriptEngine2) rEngine).eval(loadCode);
      // } catch (ScriptException e) {
      //
      // if (!this.userCanceled)
      // throw new RSessionWrapperException(errorMsg);
      // }

    }
  }
 
Example #7
Source File: RSessionWrapper.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public void loadPackage(String packageName) throws RSessionWrapperException {

    String loadCode = "library(" + packageName + ", logical.return = TRUE)";

    if (TRY_MODE)
      loadCode = "try(" + loadCode + ", silent=TRUE)";

    String errorMsg = "The \"" + this.callerFeatureName + "\" requires " + "the \"" + packageName
        + "\" R package, which couldn't be loaded - is it installed in R?";

    if (this.rEngineType == REngineType.RSERVE) {

      if (this.session != null && !this.userCanceled) {
        LOG.log(logLvl, "Loading package '" + packageName + "'...");
        int loaded = 0;
        try {

          REXP r = ((RConnection) this.rEngine).eval(loadCode);
          if (r.inherits("try-error")) {
            LOG.severe("R Error [0]: " + r.asString());
            LOG.severe("R eval attempt [0]: " + loadCode);
          }
          loaded = r.asInteger();
          LOG.log(logLvl, "Load status: '" + (loaded != 0) + "'.");

        } catch (RserveException | REXPMismatchException e) {
          LOG.log(logLvl, "Loaded package KO: '" + e.getMessage() + "'.");
          // Remain silent if eval KO ("server down").
          loaded = Integer.MIN_VALUE;
        }

        // Throw loading failure only if eval OK, but return FALSE
        // (package not loaded).
        // ("server down" case will be handled soon enough).
        if (loaded == 0)
          if (!this.userCanceled)
            throw new RSessionWrapperException(errorMsg);

        LOG.log(logLvl, "Loaded package: '" + packageName + "'.");
      }

    } else { // RCaller

      ((RCaller) rEngine).getRCode().addRCode(loadCode);
      // try {
      //
      // ((RCallerScriptEngine2) rEngine).eval(loadCode);
      // } catch (ScriptException e) {
      //
      // if (!this.userCanceled)
      // throw new RSessionWrapperException(errorMsg);
      // }

    }
  }