|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.rosuda.REngine.REngine
org.rosuda.REngine.JRI.JRIEngine
public class JRIEngine
JRIEngine is a REngine implementation using JRI (Java/R Interface).
Note that at most one JRI instance can exist in a given JVM process, because R does not support multiple threads. JRIEngine itself is thread-safe, so it is possible to invoke its methods from any thread. However, this is achieved by serializing all entries into R, so be aware of possible deadlock conditions if your R code calls back into Java (JRIEngine is re-entrant from the same thread so deadlock issues can arise only with multiple threads inteacting thorugh R).
| Field Summary | |
|---|---|
REXPReference |
baseEnv
special, global references |
REXPReference |
emptyEnv
special, global references |
REXPReference |
globalEnv
special, global references |
REXPNull |
nullValue
canonical NULL object |
REXPReference |
nullValueRef
special, global references |
static long |
requiredAPIversion
minimal JRI API version that is required by this class in order to work properly (currently API 1.10, corresponding to JRI 0.5-1 or higher) |
| Fields inherited from class org.rosuda.REngine.REngine |
|---|
lastEngine |
| Constructor Summary | |
|---|---|
JRIEngine()
default constructor - this constructor is also used via createEngine factory call and implies --no-save R argument, no callbacks and no REPL. |
|
JRIEngine(Rengine eng)
WARNING: legacy fallback for hooking from R into an existing Rengine - do NOT use for creating a new Rengine - it will go away eventually |
|
JRIEngine(java.lang.String[] args)
create JRIEngine with specified R command line arguments, no callbacks and no REPL. |
|
JRIEngine(java.lang.String[] args,
REngineCallbacks callbacks,
boolean runREPL)
creates a JRI engine with specified delegate for callbacks |
|
JRIEngine(java.lang.String[] args,
RMainLoopCallbacks callbacks)
creates a JRI engine with specified delegate for callbacks (JRI compatibility mode ONLY!). |
|
JRIEngine(java.lang.String[] args,
RMainLoopCallbacks callbacks,
boolean runREPL)
creates a JRI engine with specified delegate for callbacks (JRI compatibility mode ONLY! |
|
| Method Summary | |
|---|---|
void |
assign(java.lang.String symbol,
REXP value,
REXP env)
assign into an environment |
boolean |
close()
performs a close operation on engines that support it. |
static REngine |
createEngine()
factory method called by engineForClass |
static REngine |
createEngine(java.lang.String[] args,
REngineCallbacks callbacks,
boolean runREPL)
|
REXP |
createReference(REXP value)
create a reference by pushing local data to R and returning a reference to the data. |
REXPReference |
createRJavaRef(java.lang.Object o)
creates a jobjRef reference in R via rJava. |
REXP |
eval(REXP what,
REXP where,
boolean resolve)
evaluate an expression vector |
void |
finalizeReference(REXP ref)
removes reference from the R side. |
REXP |
get(java.lang.String symbol,
REXP env,
boolean resolve)
get a value from an environment |
REXP |
getParentEnvironment(REXP env,
boolean resolve)
get the parent environemnt of an environemnt |
Rengine |
getRni()
|
int |
lock()
obains a lock for this R engine, waiting until it becomes available. |
REXP |
newEnvironment(REXP parent,
boolean resolve)
create a new environemnt |
REXP |
parse(java.lang.String text,
boolean resolve)
parse a string into an expression vector |
void |
rBusy(Rengine re,
int which)
called when R enters or exits a longer evaluation. |
java.lang.String |
rChooseFile(Rengine re,
int newFile)
called when R expects the user to choose a file |
REXP |
resolveReference(REXP ref)
fetch the contents of the given reference. |
void |
rFlushConsole(Rengine re)
called when R requests the console to flush any buffered output |
void |
rLoadHistory(Rengine re,
java.lang.String filename)
called to load the contents of the history |
java.lang.String |
rReadConsole(Rengine re,
java.lang.String prompt,
int addToHistory)
called when R waits for user input. |
void |
rSaveHistory(Rengine re,
java.lang.String filename)
called to save the contents of the history (the implementation is responsible of keeping track of the history) |
void |
rShowMessage(Rengine re,
java.lang.String message)
called when R want to show a warning/error message (not to be confused with messages displayed in the console output) |
void |
rWriteConsole(Rengine re,
java.lang.String text,
int oType)
JRI callbacks forwarding |
boolean |
supportsEnvironments()
check whether this engine supports handing of environments (if not, REngine.eval(org.rosuda.REngine.REXP, org.rosuda.REngine.REXP, boolean) and REngine.assign(java.lang.String, org.rosuda.REngine.REXP, org.rosuda.REngine.REXP) only support the global environment denoted by null). |
boolean |
supportsLocking()
check whether this engine supports locking ( REngine.lock(), REngine.tryLock() and REngine.unlock(int)). |
boolean |
supportsReferences()
check whether this engine supports references to R objects |
int |
tryLock()
attempts to obtain a lock for this R engine synchronously (without waiting for it). |
void |
unlock(int lockValue)
releases a lock previously obtained by lock() or tryLock(). |
| Methods inherited from class org.rosuda.REngine.REngine |
|---|
assign, assign, assign, assign, assign, assign, engineForClass, engineForClass, getLastEngine, parseAndEval, parseAndEval, supportsREPL, toString, wrap |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final long requiredAPIversion
public REXPReference globalEnv
public REXPReference emptyEnv
public REXPReference baseEnv
public REXPReference nullValueRef
public REXPNull nullValue
| Constructor Detail |
|---|
public JRIEngine()
throws REngineException
createEngine factory call and implies --no-save R argument, no callbacks and no REPL.
This is equivalent to JRIEngine(new String[] { "--no-save" }, null, false)
REngineException
public JRIEngine(java.lang.String[] args)
throws REngineException
JRIEngine with specified R command line arguments, no callbacks and no REPL.
This is equivalent to JRIEngine(args, null, false)
REngineException
public JRIEngine(java.lang.String[] args,
RMainLoopCallbacks callbacks)
throws REngineException
callbacks in not null.
args - arguments to pass to R (note that R usually requires something like --no-save!)callbacks - delegate class to process event loop callback from R or null if no event loop is desired
REngineException
public JRIEngine(java.lang.String[] args,
REngineCallbacks callbacks,
boolean runREPL)
throws REngineException
args - arguments to pass to R (note that R usually requires something like --no-save!)callback - delegate class to process callbacks from R or null if no callbacks are desiredrunREPL - if set to true then the event loop (REPL) will be started, otherwise the engine is in direct operation mode.
REngineException
public JRIEngine(java.lang.String[] args,
RMainLoopCallbacks callbacks,
boolean runREPL)
throws REngineException
args - arguments to pass to R (note that R usually requires something like --no-save!)callback - delegate class to process callbacks from R or null if no callbacks are desiredrunREPL - if set to true then the event loop (REPL) will be started, otherwise the engine is in direct operation mode.
REngineException
public JRIEngine(Rengine eng)
throws REngineException
REngineException| Method Detail |
|---|
public static REngine createEngine()
throws REngineException
engineForClass
REngineException
public static REngine createEngine(java.lang.String[] args,
REngineCallbacks callbacks,
boolean runREPL)
throws REngineException
REngineExceptionpublic Rengine getRni()
public REXP parse(java.lang.String text,
boolean resolve)
throws REngineException
REngine
parse in class REnginetext - string to parseresolve - resolve the resulting REXP (true) or just return a reference (false)
REngineException
public REXP eval(REXP what,
REXP where,
boolean resolve)
throws REngineException,
REXPMismatchException
REngine
eval in class REnginewhat - an expression (or vector of such) to evaluatewhere - environment to evaluate in (use null for the global environemnt and/or if environments are not supported by the engine)resolve - resolve the resulting REXP or just return a reference
REngineException
REXPMismatchException
public void assign(java.lang.String symbol,
REXP value,
REXP env)
throws REngineException,
REXPMismatchException
REngine
assign in class REnginesymbol - symbol namevalue - value to assignenv - environment to assign to (use null for the global environemnt and/or if environments are not supported by the engine)
REngineException
REXPMismatchException
public REXP get(java.lang.String symbol,
REXP env,
boolean resolve)
throws REngineException,
REXPMismatchException
REngine
get in class REnginesymbol - symbol nameenv - environment (use null for the global environemnt and/or if environments are not supported by the engine)resolve - resolve the resulting REXP or just return a reference
REngineException
REXPMismatchException
public REXP resolveReference(REXP ref)
throws REngineException,
REXPMismatchException
REngine#REngineException exception if REngine.supportsReferences() returns false.
resolveReference in class REngineref - reference to resolve
REngineException
REXPMismatchException
public REXP createReference(REXP value)
throws REngineException,
REXPMismatchException
REngine#REngineException exception if REngine.supportsReferences() returns false.
createReference in class REnginevalue - to create reference to
REngineException
REXPMismatchException
public void finalizeReference(REXP ref)
throws REngineException,
REXPMismatchException
REngineREXPReference and should never be called directly.
finalizeReference in class REngineref - reference to finalize
REngineException
REXPMismatchException
public REXP getParentEnvironment(REXP env,
boolean resolve)
throws REngineException,
REXPMismatchException
REngine
getParentEnvironment in class REngineenv - environment to queryresolve - whether to resolve the resulting environment reference
REngineException
REXPMismatchException
public REXP newEnvironment(REXP parent,
boolean resolve)
throws REXPMismatchException,
REngineException
REngine
newEnvironment in class REngineparent - parent environmentresolve - whether to resolve the reference to the environemnt (usually false since the returned environment will be empty)
REXPMismatchException
REngineExceptionpublic boolean close()
REngineclose() returned true. This operation is optional and will always return false if not implemented.
close in class REnginetrue if the close opetaion was successful, false otherwise.public int tryLock()
tryLock in class REngineunlock(int).public int lock()
lock in class REngineunlock(int) in order to release the lockpublic void unlock(int lockValue)
lock() or tryLock().
unlock in class REnginelockValue - value returned by lock() or tryLock().public boolean supportsReferences()
REngine
supportsReferences in class REnginetrue if this engine supports references, false/code> otherwisepublic boolean supportsEnvironments()
REngineREngine.eval(org.rosuda.REngine.REXP, org.rosuda.REngine.REXP, boolean) and REngine.assign(java.lang.String, org.rosuda.REngine.REXP, org.rosuda.REngine.REXP) only support the global environment denoted by null).
supportsEnvironments in class REnginetrue if this engine supports environments, false/code> otherwisepublic boolean supportsLocking()
REngineREngine.lock(), REngine.tryLock() and REngine.unlock(int)).
supportsLocking in class REnginetrue if this engine supports REPL, false/code> otherwise
public REXPReference createRJavaRef(java.lang.Object o)
throws REngineException
jobjRef reference in R via rJava.eval("{library(rJava);.jinit()}",false), otherwise this will fail. Requires rJava 0.4-13 or higher!
o - object to push to R
jobjRef object
or null upon failure
REngineException
public void rWriteConsole(Rengine re,
java.lang.String text,
int oType)
rWriteConsole in interface RMainLoopCallbacksre - calling enginetext - text to display in the consoleoType - output type (0=regular, 1=error/warning)
public void rBusy(Rengine re,
int which)
RMainLoopCallbacks
rBusy in interface RMainLoopCallbacksre - calling enginewhich - identifies whether R enters (1) or exits (0) the busy state
public java.lang.String rReadConsole(Rengine re,
java.lang.String prompt,
int addToHistory)
RMainLoopCallbacksRengine.rniIdle() occasionally to allow other event handlers (e.g graphics device UIs) to run. Implementations should NEVER return immediately even if there is no input - such behavior will result in a fast cycling event loop which makes the use of R pretty much impossible.
rReadConsole in interface RMainLoopCallbacksre - calling engineprompt - prompt to be displayed at the console prior to user's inputaddToHistory - flag telling the handler whether the input should be considered for adding to history (!=0) or not (0)
public void rShowMessage(Rengine re,
java.lang.String message)
RMainLoopCallbacks
rShowMessage in interface RMainLoopCallbacksre - calling enginemessage - message to display
public java.lang.String rChooseFile(Rengine re,
int newFile)
RMainLoopCallbacks
rChooseFile in interface RMainLoopCallbacksre - calling enginenewFile - flag determining whether an existing or new file is to be selecteed
public void rFlushConsole(Rengine re)
RMainLoopCallbacks
rFlushConsole in interface RMainLoopCallbacksre - calling engine
public void rSaveHistory(Rengine re,
java.lang.String filename)
RMainLoopCallbacks
rSaveHistory in interface RMainLoopCallbacksre - calling enginefilename - name of the history file
public void rLoadHistory(Rengine re,
java.lang.String filename)
RMainLoopCallbacks
rLoadHistory in interface RMainLoopCallbacksre - calling enginefilename - name of the history file
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||