本文整理汇总了Java中org.rosuda.REngine.REXP.asInteger方法的典型用法代码示例。如果您正苦于以下问题:Java REXP.asInteger方法的具体用法?Java REXP.asInteger怎么用?Java REXP.asInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rosuda.REngine.REXP
的用法示例。
在下文中一共展示了REXP.asInteger方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isPackageLoaded
import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
* Check for package loaded in R environment.
*
* @param pack
* R package name
* @return package loading status
*/
public boolean isPackageLoaded(String pack) {
silentlyVoidEval(loadedpacks + "<-.packages()", false);
boolean isloaded = false;
try {
REXP i = silentlyEval("is.element(set=" + loadedpacks + ",el='"
+ pack + "')");
if (i != null) {
isloaded = i.asInteger() == 1;
}
} catch (REXPMismatchException ex) {
log(HEAD_ERROR + ex.getMessage()
+ "\n isPackageLoaded(String pack=" + pack + ")",
Level.ERROR);
}
if (isloaded) {
log(_PACKAGE_ + pack + " is loaded.", Level.INFO);
} else {
log(_PACKAGE_ + pack + " is not loaded.", Level.INFO);
}
// silentlyEval("rm(" + loadedpacks + ")");
return isloaded;
}
示例2: typeOf
import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
*
* @param robject
* R object name
* @return R type of object
*/
public String typeOf(String robject) {
if (robject == null) {
return "NULL";
}
for (String t : types) {
REXP is = silentlyEval("is." + t + "(" + robject + ")");
try {
if (is != null && is.asInteger() == 1) {
return t;
}
} catch (REXPMismatchException ex) {
log(HEAD_ERROR + "[typeOf] " + robject + " type unknown.",
Level.ERROR);
return null;
}
}
return "unknown";
}
示例3: removeFile
import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
/**
* Remove a file on the RServer.
* @param filename File to remove
*/
public void removeFile(final String filename) throws REngineException {
// Test if the file exists
final RConnection c = getRConnection();
try {
REXP exists = c.eval("file.exists(\"" + filename + "\")");
if (exists.asInteger() == 1) {
c.voidEval("file.remove(\"" + filename + "\")");
}
} catch (RserveException | REXPMismatchException e) {
throw new REngineException(c, "RServe exception: " + e);
}
}
示例4: getBoolean
import org.rosuda.REngine.REXP; //导入方法依赖的package包/类
@Override
public boolean getBoolean(final String variable) {
try {
final REXP rexp = engine.unwrap().eval(variable);
return rexp.asInteger() > 0;
} catch (final REXPMismatchException e) {
throw new RuntimeException(e);
}
}
示例5: 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);
}
}
示例6: 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);
// }
}
}