public class RSessionImpl extends java.lang.Object implements RSessionAPI, org.rosuda.REngine.REngineCallbacks, org.rosuda.REngine.REngineOutputInterface
This class should not be used directly. Instead, the weka.core.RSession class should be used - especially if running inside a system where multiple class loaders/plugins are used. This will ensure that the native libraries and supporting JRI classes get loaded by the root class loader and are thus available to all child class loaders.
For R to be available to Weka it is necessary for the user to:
Constructor and Description |
---|
RSessionImpl() |
Modifier and Type | Method and Description |
---|---|
static RSessionAPI |
acquireSession(java.lang.Object requester)
Acquire the session for the requester
|
void |
assign(java.lang.Object requester,
java.lang.String var,
byte[] val)
Wraps REngine.assign
|
void |
assign(java.lang.Object requester,
java.lang.String var,
double[] val)
Wraps REngine.assign
|
void |
assign(java.lang.Object requester,
java.lang.String var,
int[] val)
Wraps REngine.assign
|
void |
assign(java.lang.Object requester,
java.lang.String var,
org.rosuda.REngine.REXP val)
Wraps REngine.assign
|
void |
assign(java.lang.Object requester,
java.lang.String var,
java.lang.String[] val)
Wraps REngine.assign
|
void |
clearConsoleBuffer(java.lang.Object requester)
Clear the contents of the R console buffer
|
void |
close() |
org.rosuda.REngine.REXP |
createReference(java.lang.Object requester,
org.rosuda.REngine.REXP source)
Pushes an REXP back into R and, if successful, returns a reference REXP
that points to the pushed object in R.
|
void |
dropSession(java.lang.Object requester) |
org.rosuda.REngine.REXP |
get(java.lang.Object requester,
java.lang.String var)
Get a named object from R.
|
java.lang.String |
getConsoleBuffer(java.lang.Object requester)
Get the contents of the R console buffer
|
RSessionAPI |
getSession(java.lang.Object requester) |
static RSessionAPI |
getSessionSingleton()
Get the reference to the singleton.
|
RSessionAPI |
init()
Initialization routine.
|
boolean |
installLibrary(java.lang.Object requester,
java.lang.String libraryName)
Convenience method for getting R to install a library.
|
boolean |
installLibrary(java.lang.Object requester,
java.lang.String libraryName,
java.lang.String repos)
Convenience method for getting R to install a library.
|
boolean |
isVariableSet(java.lang.Object requester,
java.lang.String var)
Check if a named variable is set in the R environment
|
boolean |
loadLibrary(java.lang.Object requester,
java.lang.String libraryName)
Convenience method for getting R to load a named library.
|
org.rosuda.REngine.REXP |
parseAndEval(java.lang.Object requester,
java.lang.String cmd)
Wraps REngine.parseAndEval.
|
static boolean |
rAvailable()
Checks if R is available
|
static void |
releaseSession(java.lang.Object requester)
Release the session so that other clients can obtain it.
|
void |
RFlushConsole(org.rosuda.REngine.REngine eng)
called by R to flush (display) any pending console output.
|
void |
RShowMessage(org.rosuda.REngine.REngine eng,
java.lang.String text)
called when R wants to show a warning/error message box (not
console-related).
|
void |
RWriteConsole(org.rosuda.REngine.REngine eng,
java.lang.String text,
int oType)
called when R prints output to the console.
|
void |
setLog(java.lang.Object requester,
RLoggerAPI log)
Set the logger to use
|
public RSessionAPI init() throws java.lang.Exception
init
in interface RSessionAPI
java.lang.Exception
public static RSessionAPI getSessionSingleton()
public void setLog(java.lang.Object requester, RLoggerAPI log) throws RSessionException
setLog
in interface RSessionAPI
requester
- the object registering the log (must be the current
session holder)log
- the log to useRSessionException
- if the requester is not the current session
holderpublic void clearConsoleBuffer(java.lang.Object requester) throws RSessionException
clearConsoleBuffer
in interface RSessionAPI
requester
- the requesting object (must be the session holder)RSessionException
- if the requester is not the session holderpublic java.lang.String getConsoleBuffer(java.lang.Object requester) throws RSessionException
getConsoleBuffer
in interface RSessionAPI
requester
- the requesting object (must be the session holder)RSessionException
- if the requester is not the session holderpublic RSessionAPI getSession(java.lang.Object requester) throws java.lang.Exception
getSession
in interface RSessionAPI
java.lang.Exception
public void dropSession(java.lang.Object requester)
dropSession
in interface RSessionAPI
public static boolean rAvailable()
public static RSessionAPI acquireSession(java.lang.Object requester) throws java.lang.Exception
requester
- the object requesting the sessionjava.lang.Exception
- if the session is currently held by another clientpublic static void releaseSession(java.lang.Object requester)
requester
- the session holderpublic boolean loadLibrary(java.lang.Object requester, java.lang.String libraryName) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
loadLibrary
in interface RSessionAPI
requester
- the requesting objectlibraryName
- the name of the library to loadRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endorg.rosuda.REngine.REXPMismatchException
- if a problem occurs on the R endpublic boolean installLibrary(java.lang.Object requester, java.lang.String libraryName) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
installLibrary
in interface RSessionAPI
requester
- the requesting objectlibraryName
- the name of the library to installRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endorg.rosuda.REngine.REXPMismatchException
- if a problem occurs on the R endpublic boolean installLibrary(java.lang.Object requester, java.lang.String libraryName, java.lang.String repos) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
installLibrary
in interface RSessionAPI
requester
- the requesting objectlibraryName
- the name of the library to installrepos
- the repository(s) to useRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endorg.rosuda.REngine.REXPMismatchException
- if a problem occurs on the R endpublic boolean isVariableSet(java.lang.Object requester, java.lang.String var) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
isVariableSet
in interface RSessionAPI
requester
- the requesting objectvar
- the name of the variable to checkRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R sideorg.rosuda.REngine.REXPMismatchException
- if a problem occurs on the R sidepublic org.rosuda.REngine.REXP createReference(java.lang.Object requester, org.rosuda.REngine.REXP source) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
createReference
in interface RSessionAPI
requester
- the requesting objectsource
- the source object to push into RRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endorg.rosuda.REngine.REXPMismatchException
- if a problem occurs on the R endpublic org.rosuda.REngine.REXP get(java.lang.Object requester, java.lang.String var) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
get
in interface RSessionAPI
requester
- the requesting objectvar
- the name of the variable in R to getRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endorg.rosuda.REngine.REXPMismatchException
- if a problem occurs on the R endpublic void assign(java.lang.Object requester, java.lang.String var, org.rosuda.REngine.REXP val) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
assign
in interface RSessionAPI
requester
- the requesting objectvar
- the name of the variable to assign toval
- an REXP objectRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endorg.rosuda.REngine.REXPMismatchException
public void assign(java.lang.Object requester, java.lang.String var, byte[] val) throws RSessionException, org.rosuda.REngine.REngineException
assign
in interface RSessionAPI
requester
- the requesting objectvar
- the name of the variable to assign toval
- a byte[] valueRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endpublic void assign(java.lang.Object requester, java.lang.String var, double[] val) throws RSessionException, org.rosuda.REngine.REngineException
assign
in interface RSessionAPI
requester
- the requesting objectvar
- the name of the variable to assign toval
- a double[] valueRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endpublic void assign(java.lang.Object requester, java.lang.String var, int[] val) throws RSessionException, org.rosuda.REngine.REngineException
assign
in interface RSessionAPI
requester
- the requesting objectvar
- the name of the variable to assign toval
- a int[] valueRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endpublic void assign(java.lang.Object requester, java.lang.String var, java.lang.String[] val) throws RSessionException, org.rosuda.REngine.REngineException
assign
in interface RSessionAPI
requester
- the requesting objectvar
- the name of the variable to assign toval
- a String[] valueRSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endpublic org.rosuda.REngine.REXP parseAndEval(java.lang.Object requester, java.lang.String cmd) throws RSessionException, org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
parseAndEval
in interface RSessionAPI
requester
- the requesting objectcmd
- the command(s)RSessionException
- if the requester is not the current session
holderorg.rosuda.REngine.REngineException
- if a problem occurs on the R endorg.rosuda.REngine.REXPMismatchException
- if a problem occurs on the R endpublic void RFlushConsole(org.rosuda.REngine.REngine eng)
RFlushConsole
in interface org.rosuda.REngine.REngineOutputInterface
eng
- calling enginepublic void RShowMessage(org.rosuda.REngine.REngine eng, java.lang.String text)
RShowMessage
in interface org.rosuda.REngine.REngineOutputInterface
eng
- calling enginetext
- text to display in the messagepublic void RWriteConsole(org.rosuda.REngine.REngine eng, java.lang.String text, int oType)
RWriteConsole
in interface org.rosuda.REngine.REngineOutputInterface
eng
- calling enginetext
- text to display in the consoleoType
- output type (0=regular, 1=error/warning)public void close()
close
in interface RSessionAPI