当前位置: 首页>>代码示例>>Java>>正文


Java REXP.inherits方法代码示例

本文整理汇总了Java中org.rosuda.REngine.REXP.inherits方法的典型用法代码示例。如果您正苦于以下问题:Java REXP.inherits方法的具体用法?Java REXP.inherits怎么用?Java REXP.inherits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.rosuda.REngine.REXP的用法示例。


在下文中一共展示了REXP.inherits方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeStringFunction

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
 * Executes an R function (return: String)
 * 
 * @param function
 *        name of the R function
 * @param parameters
 *        array of parameters required by the function
 * 
 *        TODO: make more generic - not just for Strings ...
 */
public static String executeStringFunction(RConnection conn, String function, String[] parameters) {

    try {
        // create request
        String request = "try(" + function + "(";
        for (String parameter : parameters) {
            request += parameter + ",";
        }
        // remove last ","
        request = request.substring(0, request.length() - 1);
        request += "))";
        // execute function
        REXP xp = conn.parseAndEval(request);
        if (xp.inherits("try-error")) {
            close(conn);
            throw new IOException("failed to execute function '" + function + "'; \nrequest: " + request
                    + "; \nError: " + xp.asString());
        }
        String retval = xp.asString();
        return retval;
    }
    catch (Exception e) {
        return null;
    }
}
 
开发者ID:52North,项目名称:movingcode,代码行数:36,代码来源:RServerController.java

示例2: getRServeConnection

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
 * Get an R connection
 * 
 * @param host
 * @param workspace
 * @return {@link RConnection} rConnection - a connection to RServer
 */
private static RConnection getRServeConnection(String host, String workspace) {

    try {
        // establish R connection
        RConnection conn = new RConnection(host);
        // check connection
        if (conn == null || !conn.isConnected())
            throw new IOException("Failed to establish RServe connection");

        // set workspace
        if (workspace != null) {
            REXP xp = conn.parseAndEval("try(setwd('" + workspace.replace("\\", "\\\\") + "'))");
            if (xp.inherits("try-error"))
                throw new IOException("Failed to load R workspace; \nError: " + xp.asString());
        }
        return conn;
    }
    catch (Exception e) {
        return null;
    }
}
 
开发者ID:52North,项目名称:movingcode,代码行数:29,代码来源:RServerController.java

示例3: executeVoidFunction

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
 * Executes an R function (return: void)
 * 
 * @param function
 *        name of the R function
 * @param Parameters
 *        array of parameters required by the function
 */
public static boolean executeVoidFunction(RConnection conn, String function, String[] parameters) {
    // create request
    try {
        String request = "try(" + function + "(";
        if (parameters.length != 0) {
            for (String parameter : parameters) {
                request += parameter + ",";
            }
            // remove last ","
            request = request.substring(0, request.length() - 1);
            request += "))";
        }
        // execute function
        REXP xp = conn.parseAndEval(request);
        if (xp.inherits("try-error")) {
            close(conn);
            throw new IOException("failed to execute function '" + function + "'; \nrequest: " + request
                    + "; \nError: " + xp.asString());
        }
        return true;
    }
    catch (Exception e) {
        return false;
    }

}
 
开发者ID:52North,项目名称:movingcode,代码行数:35,代码来源:RServerController.java

示例4: loadRDataWorkspace

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
 * Load RData workspace
 * 
 * @param RData
 *        Name of the RData file, relative to R workspace
 */
private static boolean loadRDataWorkspace(RConnection conn, String rData) {
    // load specified RData file from workspace
    try {
        REXP xp = conn.parseAndEval("try(load(paste(getwd(),'" + rData + "',sep='/')))");
        if (xp.inherits("try-error")) {
            throw new IOException("failed to load RData workspace; \nError: " + xp.toString());
        }
        return true;
    }
    catch (Exception e) {
        return false;
    }

}
 
开发者ID:52North,项目名称:movingcode,代码行数:21,代码来源:RServerController.java

示例5: close

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
 * Close R connection
 */
private static void close(RConnection conn) {
    try {
        REXP xp = conn.parseAndEval("gc()");
        if (xp.inherits("try-error")) {
            throw new IOException("failed to load R workspace; \nError: " + xp.asString());
        }
        conn.close();
    }
    catch (Exception e) {
        // do nothing
        // should not occur
        // TODO: ...
    }
}
 
开发者ID:52North,项目名称:movingcode,代码行数:18,代码来源:RServerController.java

示例6: eval

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
@Override
public <T> T eval(String command) throws FOSException {
    try {
        if(logger.isTraceEnabled()) {
            logger.trace(command);
        }

        connection.assign("trycodeblock", command);

        REXP result = connection.parseAndEval("try(eval(parse(text=trycodeblock)),silent=TRUE)");
        if (result != null && result.inherits("try-error")) {
            throw new FOSException(result.toDebugString());
        }
        if (result == null || result.isNull()) {
            return null;
        } else if( result.isVector() && result.isNumeric()) {
          return (T) result.asDoubles();
        } else if (result.isInteger()) {
            return (T) new Integer(result.asInteger());
        } else if (result.isNumeric()) {
            return (T) new Double(result.asDouble());
        } else if (result.isString()) {
            return (T) result.asString();
        }
        return null;
    } catch (Exception e) {
        throw new FOSException("Error executing R script.", e);
    }
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:30,代码来源:FosRserve.java

示例7: tryEval

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
public REXP tryEval(RConnection c, String s) throws RserveException,  
RException, REXPMismatchException {
	//  silent: logical: should the report of error messages be suppressed
   REXP r  = c.eval("try({" + s + "}, silent=TRUE)");
   if (r.inherits("try-error")) throw new RException(r.asString());
   return r;
}
 
开发者ID:hmsiccbl,项目名称:screensaver,代码行数:8,代码来源:RserveExtensions.java

示例8: loadPackage

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
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);
//			}

        }
    }
 
开发者ID:mzmine,项目名称:mzmine2,代码行数:58,代码来源:RSessionWrapper.java

示例9: getStream

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
public InputStream getStream() {
	try {

		semaphore.acquire();
		// System.out.println("Semaphore acquired");
		// System.out.flush();

		/* The R Cairo package is used for high-quality graphics */
		boolean CairoOK = rc.parseAndEval(
				"suppressWarnings(require('Cairo',quietly=TRUE))")
				.asInteger() > 0;
		if (!CairoOK) {
			System.err.println("RVaadin: Could not find Cairo package");
			rc.parseAndEval("cat('RVaadin: Error: "
					+ "Could not find Cairo package.\n')");
		}

		/*
		 * Observe the usage of R's try and error mechanism in Java, and
		 * remember that device == 'png', 'pdf', ...
		 */
		REXP xp = rc.parseAndEval("try(Cairo" + device.toUpperCase()
				+ "('tmp." + device + "', " + "width=" + width
				+ ", height=" + height + "))");

		if (xp.inherits("try-error")) {

			System.err.println("Can't open " + device
					+ " graphics device:\n" + xp.asString());
			/* Plot the first warning into the error console */
			REXP w = rc.eval("if (exists('last.warning') && "
					+ "length(last.warning)>0) "
					+ "names(last.warning)[1] else 0");
			if (w.isString()) {
				System.err.println(w.asString());
			}
		}

		/*
		 * Now, state the actual plot command and then close the Cairo
		 * device to produce the graphics
		 */
		rc.parseAndEval(RPlotCall);
		rc.parseAndEval("dev.off()");

		/*
		 * The author of RServe claims that there is no I/O API for REngine
		 * as it's actually more efficient to use R.
		 */

		String fileName = "tmp." + device;

		xp = rc.parseAndEval("r <- readBin('" + fileName
				+ "','raw', file.info('" + fileName + "')$size); "
				+ "unlink('" + fileName + "'); r");

		return new ByteArrayInputStream(xp.asBytes());

	} catch (RserveException rse) {
		/* RserveException (transport layer - e.g. Rserve is not running */
		System.out.println(rse);
		return null;

	} catch (REXPMismatchException mme) {
		/* REXP mismatch exception (we got something else as expected) */
		System.out.println(mme);
		mme.printStackTrace();
		return null;

	} catch (Exception e) {
		/* something else */
		System.err.println("Errors in RPLotCall: " + e.getMessage());
		e.printStackTrace();
		return null;

	} finally {
		semaphore.release();
		// System.out.println("Semaphore released");
		// System.out.flush();
	}
}
 
开发者ID:avirkki,项目名称:RVaadin,代码行数:82,代码来源:RImageSource.java


注:本文中的org.rosuda.REngine.REXP.inherits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。