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


Java REXP.isString方法代码示例

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


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

示例1: getNumbers

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
private Integer[] getNumbers(REXP ids) {
	if(ids.isString()) {
		return Arrays.stream(((REXPString)ids).asStrings())//NOSONAR: This stream doesn't need to be closed
					.map(
							id -> {
								if(id != null) {
									return Integer.valueOf(id);
								} else {
									return null;
								}
							}
					).toArray(Integer[]::new);
	} else {
		int[] idsAsArray = ((REXPInteger)ids).asIntegers();
		return (Integer[])Arrays.stream(idsAsArray).boxed().toArray(Integer[]::new);//NOSONAR: This stream doesn't need to be closed
	}
}
 
开发者ID:jfcorugedo,项目名称:RJavaServer,代码行数:18,代码来源:RServiceImpl.java

示例2: 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

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