本文整理汇总了Java中org.rosuda.REngine.Rserve.RConnection.parseAndEval方法的典型用法代码示例。如果您正苦于以下问题:Java RConnection.parseAndEval方法的具体用法?Java RConnection.parseAndEval怎么用?Java RConnection.parseAndEval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rosuda.REngine.Rserve.RConnection
的用法示例。
在下文中一共展示了RConnection.parseAndEval方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeStringFunction
import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的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;
}
}
示例2: getRServeConnection
import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的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;
}
}
示例3: RContainer
import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的package包/类
/**
* <p>
* The RContainer constructor opens a connection (an RConnection) to either
* local or remote RServe, and combines the object with the current Vaadin
* main window. Thus, the main window must have been set earlier with
* {@link com.vaadin.Application#setMainWindow(Window)} for the grahics to
* work. See {@link RContainer#RContainer(Application, String, int)} for
* accessing remote R Servers.
* </p>
*
* <p>
* Example:<br>
* {@code Window main = new Window("My Fabulous Analysis App");}<br>
* {@code setMainWindow(main);}<br>
* {@code RContainer R = new RContainer(main.getApplication());}
* </p>
*
* @param app
* Vaadin Application reference. Needed in the construction of
* StreamResource objects for R graphics.
*/
public RContainer() {
try {
rc = new RConnection();
rc.parseAndEval("library('Cairo')");
} catch (Exception e) {
if (verboseErrors) {
Notification.show("RVaadin: Could not connect to R.",
Notification.Type.ERROR_MESSAGE);
}
e.printStackTrace();
}
/*
* Random session identifier for this particular R connection (used to
* e.g. tell the browser not to cache the images)
*/
rand = new Random((new GregorianCalendar()).getTimeInMillis());
String chars = "abcdefghijklmnopqrstuvwxyz";
sessionID = getRandomString(rand, chars, 10);
}
示例4: executeVoidFunction
import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的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;
}
}
示例5: loadRDataWorkspace
import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的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;
}
}
示例6: close
import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的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: ...
}
}