Package org.math.R
Class RserveSession
- java.lang.Object
-
- org.math.R.Rsession
-
- org.math.R.RserveSession
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.math.R.Rsession
Rsession.Function, Rsession.RException
-
Nested classes/interfaces inherited from interface org.math.R.RLog
RLog.Level
-
-
Field Summary
Fields Modifier and Type Field Description booleanconnectedstatic StringHEAD_SETstatic intMinRserveVersionRserverConfRserveConfStringstatusstatic StringSTATUS_CONNECTINGstatic StringSTATUS_ENDEDstatic StringSTATUS_ERRORstatic StringSTATUS_NOT_CONNECTEDstatic StringSTATUS_NOT_SETstatic StringSTATUS_READY-
Fields inherited from class org.math.R.Rsession
_PACKAGE_, CAST_ERROR, debug, DEFAULT_REPOS, envName, GRAPHIC_BMP, GRAPHIC_JPEG, GRAPHIC_PNG, GRAPHIC_TIFF, HEAD_TRY, PACKAGEINSTALLED, PACKAGELOADED, repos, SAVE_ASCII, TRY_MODE, TRY_MODE_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description RserveSession(PrintStream p, Properties properties, RserverConf serverconf)create rsession using System as a loggerRserveSession(RLog console, Properties properties, RserverConf serverconf)create a new Rsession.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description double[]asArray(Object o)doubleasDouble(Object o)intasInteger(Object o)int[]asIntegers(Object o)MapasList(Object o)booleanasLogical(Object o)boolean[]asLogicals(Object o)double[][]asMatrix(Object o)StringasR2HTML(String command)Get R command text output in HTML formatstatic org.rosuda.REngine.REXPListasRList(Map m)StringasString(Object o)String[]asStrings(Object o)Objectcast(Object o)static Stringcat(org.rosuda.REngine.RList list)voidcopyGlobalEnv(String envName)voidend()correctly (depending on execution platform) shutdown Rsession.voidgetFile(File localfile)Get file from R environment to user filesystemvoidgetFile(File localfile, String remoteFile)Get file from R environment to user filesystemvoidgetFileFromWorkspace(File file)Stringgethomedir()StringgetLastError()StringgetRServeOS()StringgetStatus()booleanisAvailable()booleanisLinux()booleanisMacOSX()booleanisNull(Object o)booleanisWindows()static voidmain(String[] args)static RserveSessionnewInstanceTry(PrintStream pconsole, RserverConf serverconf)Deprecated.Use new RserveSession standard constructor insteadstatic RserveSessionnewInstanceTry(RLog console, RserverConf serverconf)Deprecated.Use new RserveSession standard constructor insteadstatic RserveSessionnewLocalInstance(PrintStream pconsole, Properties localRProperties)Deprecated.Use new RserveSession standard constructor insteadstatic RserveSessionnewLocalInstance(RLog console, Properties localRProperties)Deprecated.Use new RserveSession standard constructor insteadstatic RserveSessionnewRemoteInstance(PrintStream pconsole, RserverConf serverconf)Deprecated.Use new RserveSession standard constructor insteadstatic RserveSessionnewRemoteInstance(RLog console, RserverConf serverconf)Deprecated.Use new RserveSession standard constructor insteadObjectproxyEval(String expression, Map<String,Object> vars)Method to rawEval expression.FileputFile(File localfile)Send user filesystem file in r environement (like data)FileputFile(File localfile, String remoteFile)Send user filesystem file in r environement (like data)FileputFileInWorkspace(File file)voidsave(File f, String... vars)Save R variables in data filevoidsavels(File f, String... vars)Save R variables in data filebooleanset(String varname, double[][] data, String... names)Set R data.frame in R env.booleanset(String varname, Object var)Set R object in R env.voidsetGlobalEnv(String envName)protected ObjectsilentlyRawEval(String expression, boolean tryEval)Silently (ie no log) launch R command and return value.protected booleansilentlyVoidEval(String expression, boolean tryEval)Silently (ie no log) launch R command without return value.voidtoGraphic(File f, int width, int height, String fileformat, String... commands)Create a file for R graphical command outputprotected static StringtoRcode(Object o)protected static StringtoRcode(org.rosuda.REngine.RList l)StringtoString(Object o)-
Methods inherited from class org.math.R.Rsession
addBusyListener, addEvalListener, addLogger, addUpdateObjectsListener, asHTML, buildList, buildListPattern, buildListString, cat, cat, cat, cat, cat, cat, cat, closeLog, eval, eval, finalize, getGlobalEnv, getLastLogEntry, getLastOutput, getRepository, getwd, hash, installPackage, installPackage, installPackage, installPackages, isPackageInstalled, isPackageLoaded, listCommands, load, loadPackage, local2remotePath, log, ls, ls, ls, note_code, note_code, note_header, note_text, notebook, print, rawEval, rawEval, remote2localPath, removeBusyListener, removeEvalListener, removeLogger, removeUpdateObjectsListener, reshapeAsRow, reshapeAsRow, rm, rmAll, rmAll, rmls, set, setBusy, setCRANRepository, setRepository, setwd, silentlyRawEval, silentlyVoidEval, sinkMessage, sinkOutput, source, t, toBMP, toGraphic, toHTML, toJPEG, toPNG, toRcode, toRcode, toRcode, toRcode, toRcode, toRcode, toRpath, toRpath, toTIFF, typeOf, unset, unset, voidEval, voidEval
-
-
-
-
Field Detail
-
MinRserveVersion
public static final int MinRserveVersion
- See Also:
- Constant Field Values
-
connected
public boolean connected
-
RserveConf
public RserverConf RserveConf
-
STATUS_NOT_SET
public static final String STATUS_NOT_SET
- See Also:
- Constant Field Values
-
STATUS_READY
public static final String STATUS_READY
- See Also:
- Constant Field Values
-
STATUS_ERROR
public static final String STATUS_ERROR
- See Also:
- Constant Field Values
-
STATUS_ENDED
public static final String STATUS_ENDED
- See Also:
- Constant Field Values
-
STATUS_NOT_CONNECTED
public static final String STATUS_NOT_CONNECTED
- See Also:
- Constant Field Values
-
STATUS_CONNECTING
public static final String STATUS_CONNECTING
- See Also:
- Constant Field Values
-
status
public String status
-
HEAD_SET
public static final String HEAD_SET
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RserveSession
public RserveSession(RLog console, Properties properties, RserverConf serverconf)
create a new Rsession.- Parameters:
console- PrintStream for R outputproperties- env variables to setup at R session startup (like http_proxy)serverconf- RserverConf server configuration object, giving IP, port, login, password
-
RserveSession
public RserveSession(PrintStream p, Properties properties, RserverConf serverconf)
create rsession using System as a logger- Parameters:
p- PrintStreamproperties- R session properties to setup (like hhtp_proxy)serverconf- RserverConf
-
-
Method Detail
-
cat
public static String cat(org.rosuda.REngine.RList list)
-
newLocalInstance
public static RserveSession newLocalInstance(RLog console, Properties localRProperties)
Deprecated.Use new RserveSession standard constructor insteadBuild a new local Rsession- Parameters:
console- PrintStream for R outputlocalRProperties- properties to pass to R (eg http_proxy or R libpath)- Returns:
- RserveSession instanciated
-
newRemoteInstance
public static RserveSession newRemoteInstance(RLog console, RserverConf serverconf)
Deprecated.Use new RserveSession standard constructor insteadBuild a new remote Rsession- Parameters:
console- PrintStream for R outputserverconf- RserverConf server configuration object, giving IP, port, login, password, properties to pass to R (eg http_proxy or R libpath)- Returns:
- RserveSession instanciated
-
newInstanceTry
public static RserveSession newInstanceTry(RLog console, RserverConf serverconf)
Deprecated.Use new RserveSession standard constructor insteadBuild a new Rsession. Fork to local spawned Rsession if given remote one failed to initialized.- Parameters:
console- PrintStream for R outputserverconf- RserverConf server configuration object, giving IP, port, login, password- Returns:
- RserveSession instanciated
-
newLocalInstance
public static RserveSession newLocalInstance(PrintStream pconsole, Properties localRProperties)
Deprecated.Use new RserveSession standard constructor insteadBuild a new local Rsession- Parameters:
pconsole- PrintStream for R outputlocalRProperties- properties to pass to R (eg http_proxy or R libpath)- Returns:
- RserveSession instanciated
-
newRemoteInstance
public static RserveSession newRemoteInstance(PrintStream pconsole, RserverConf serverconf)
Deprecated.Use new RserveSession standard constructor insteadBuild a new remote Rsession- Parameters:
pconsole- PrintStream for R outputserverconf- RserverConf server configuration object, giving IP, port, login, password, properties to pass to R (eg http_proxy or R libpath)- Returns:
- RserveSession instanciated
-
newInstanceTry
public static RserveSession newInstanceTry(PrintStream pconsole, RserverConf serverconf)
Deprecated.Use new RserveSession standard constructor insteadBuild a new Rsession. Fork to local spawned Rsession if given remote one failed to initialized.- Parameters:
pconsole- PrintStream for R outputserverconf- RserverConf server configuration object, giving IP, port, login, password, properties to pass to R (eg http_proxy)- Returns:
- RserveSession instanciated
-
getStatus
public String getStatus()
- Returns:
- status of Rsession
-
end
public void end()
correctly (depending on execution platform) shutdown Rsession.
-
getLastError
public String getLastError()
- Overrides:
getLastErrorin classRsession
-
gethomedir
public String gethomedir()
- Specified by:
gethomedirin classRsession
-
silentlyVoidEval
protected boolean silentlyVoidEval(String expression, boolean tryEval)
Silently (ie no log) launch R command without return value.- Specified by:
silentlyVoidEvalin classRsession- Parameters:
expression- R expresison to evaluatetryEval- encapsulate command in try() to cacth errors- Returns:
- succeeded ?
-
silentlyRawEval
protected Object silentlyRawEval(String expression, boolean tryEval)
Silently (ie no log) launch R command and return value.- Specified by:
silentlyRawEvalin classRsession- Parameters:
expression- R expression to evaluatetryEval- encapsulate command in try() to cacth errors- Returns:
- REXP R expression
-
getRServeOS
public String getRServeOS()
-
isWindows
public boolean isWindows()
-
isLinux
public boolean isLinux()
-
isMacOSX
public boolean isMacOSX()
-
toRcode
protected static String toRcode(org.rosuda.REngine.RList l)
-
set
public boolean set(String varname, double[][] data, String... names)
Set R data.frame in R env.
-
set
public boolean set(String varname, Object var) throws Rsession.RException
Set R object in R env.- Specified by:
setin classRsession- Parameters:
varname- R object namevar- R object value- Returns:
- succeeded ?
- Throws:
Rsession.RException- Could not set var
-
asRList
public static org.rosuda.REngine.REXPList asRList(Map m)
-
asDouble
public double asDouble(Object o) throws ClassCastException
- Specified by:
asDoublein classRsession- Throws:
ClassCastException
-
asArray
public double[] asArray(Object o) throws ClassCastException
- Specified by:
asArrayin classRsession- Throws:
ClassCastException
-
asMatrix
public double[][] asMatrix(Object o) throws ClassCastException
- Specified by:
asMatrixin classRsession- Throws:
ClassCastException
-
asString
public String asString(Object o) throws ClassCastException
- Specified by:
asStringin classRsession- Throws:
ClassCastException
-
asStrings
public String[] asStrings(Object o) throws ClassCastException
- Specified by:
asStringsin classRsession- Throws:
ClassCastException
-
asInteger
public int asInteger(Object o) throws ClassCastException
- Specified by:
asIntegerin classRsession- Throws:
ClassCastException
-
asIntegers
public int[] asIntegers(Object o) throws ClassCastException
- Specified by:
asIntegersin classRsession- Throws:
ClassCastException
-
asLogical
public boolean asLogical(Object o) throws ClassCastException
- Specified by:
asLogicalin classRsession- Throws:
ClassCastException
-
asLogicals
public boolean[] asLogicals(Object o) throws ClassCastException
- Specified by:
asLogicalsin classRsession- Throws:
ClassCastException
-
asList
public Map asList(Object o) throws ClassCastException
- Specified by:
asListin classRsession- Throws:
ClassCastException
-
cast
public Object cast(Object o) throws ClassCastException
- Specified by:
castin classRsession- Throws:
ClassCastException
-
putFileInWorkspace
public File putFileInWorkspace(File file)
- Specified by:
putFileInWorkspacein classRsession
-
getFileFromWorkspace
public void getFileFromWorkspace(File file)
- Specified by:
getFileFromWorkspacein classRsession
-
save
public void save(File f, String... vars) throws Rsession.RException
Description copied from class:RsessionSave R variables in data file- Overrides:
savein classRsession- Parameters:
f- file to store data (eg ".Rdata")vars- R variables to save- Throws:
Rsession.RException- Could not do save
-
savels
public void savels(File f, String... vars) throws Rsession.RException
Description copied from class:RsessionSave R variables in data file- Overrides:
savelsin classRsession- Parameters:
f- file to store data (eg ".Rdata")vars- R variables names patterns to save- Throws:
Rsession.RException- Could not do save
-
toGraphic
public void toGraphic(File f, int width, int height, String fileformat, String... commands)
Description copied from class:RsessionCreate a file for R graphical command output
-
asR2HTML
public String asR2HTML(String command)
Description copied from class:RsessionGet R command text output in HTML format
-
getFile
public void getFile(File localfile)
Get file from R environment to user filesystem- Parameters:
localfile- file to get (same name in R env. and user filesystem)
-
getFile
public void getFile(File localfile, String remoteFile)
Get file from R environment to user filesystem- Parameters:
localfile- local filesystem fileremoteFile- R environment file name
-
putFile
public File putFile(File localfile)
Send user filesystem file in r environement (like data)- Parameters:
localfile- File to send- Returns:
- remote File object
-
putFile
public File putFile(File localfile, String remoteFile)
Send user filesystem file in r environement (like data)- Parameters:
localfile- File to sendremoteFile- filename in R env.- Returns:
- remot File object
-
proxyEval
public Object proxyEval(String expression, Map<String,Object> vars) throws Rsession.RException
Method to rawEval expression. Holds many optimizations (@see noVarsEvals) and turn around for reliable usage (like engine auto restart). 1D Numeric "vars" are replaced using Java replace engine instead of R one. Intended to not interfer with current R env vars. Yes, it's hard-code :)- Overrides:
proxyEvalin classRsession- Parameters:
expression- String to evaluatevars- HashMap<String, Object> vars inside expression. Passively overload current R env variables.- Returns:
- java castStrict Object Warning, UNSTABLE and high CPU cost.
- Throws:
Rsession.RException- Could not proxyEval with one of vars
-
isAvailable
public boolean isAvailable()
- Specified by:
isAvailablein classRsession
-
setGlobalEnv
public void setGlobalEnv(String envName)
- Specified by:
setGlobalEnvin classRsession
-
copyGlobalEnv
public void copyGlobalEnv(String envName)
- Specified by:
copyGlobalEnvin classRsession
-
-