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


Java REXP.asString方法代码示例

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


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

import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
@Override
public String getString(final String variable) {
    try {
        final REXP rexp = engine.unwrap().eval(variable);
        final boolean[] na = rexp.isNA();
        Assertions.checkEquals(na.length, 1);
        if (na[0]) {
            return null;
        } else {
            return rexp.asString();
        }
    } catch (final REXPMismatchException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:subes,项目名称:invesdwin-context-r,代码行数:16,代码来源:RserveScriptTaskResultsR.java

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

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


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