Package org.math.R

Class RserveSession

  • All Implemented Interfaces:
    RLog

    public class RserveSession
    extends Rsession
    implements RLog
    Author:
    richet
    • Constructor Detail

      • RserveSession

        public RserveSession​(RLog console,
                             Properties properties,
                             RserverConf serverconf)
        create a new Rsession.
        Parameters:
        console - PrintStream for R output
        properties - 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 - PrintStream
        properties - 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 instead
        Build a new local Rsession
        Parameters:
        console - PrintStream for R output
        localRProperties - 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 instead
        Build a new remote Rsession
        Parameters:
        console - PrintStream for R output
        serverconf - 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 instead
        Build a new Rsession. Fork to local spawned Rsession if given remote one failed to initialized.
        Parameters:
        console - PrintStream for R output
        serverconf - 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 instead
        Build a new local Rsession
        Parameters:
        pconsole - PrintStream for R output
        localRProperties - 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 instead
        Build a new remote Rsession
        Parameters:
        pconsole - PrintStream for R output
        serverconf - 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 instead
        Build a new Rsession. Fork to local spawned Rsession if given remote one failed to initialized.
        Parameters:
        pconsole - PrintStream for R output
        serverconf - 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.
        Overrides:
        end in class Rsession
      • silentlyVoidEval

        protected boolean silentlyVoidEval​(String expression,
                                           boolean tryEval)
        Silently (ie no log) launch R command without return value.
        Specified by:
        silentlyVoidEval in class Rsession
        Parameters:
        expression - R expresison to evaluate
        tryEval - 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:
        silentlyRawEval in class Rsession
        Parameters:
        expression - R expression to evaluate
        tryEval - 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.
        Specified by:
        set in class Rsession
        Parameters:
        varname - R list name
        data - numeric data in list
        names - names of columns
        Returns:
        succeeded ?
      • asRList

        public static org.rosuda.REngine.REXPList asRList​(Map m)
      • toGraphic

        public void toGraphic​(File f,
                              int width,
                              int height,
                              String fileformat,
                              String... commands)
        Description copied from class: Rsession
        Create a file for R graphical command output
        Overrides:
        toGraphic in class Rsession
        Parameters:
        f - File to store data (eg .jpg file)
        width - width of image
        height - height of image
        fileformat - format of image: png,tiff,jpeg,bmp
        commands - R command to create image (eg plot())
      • asR2HTML

        public String asR2HTML​(String command)
        Description copied from class: Rsession
        Get R command text output in HTML format
        Overrides:
        asR2HTML in class Rsession
        Parameters:
        command - R command returning text
        Returns:
        HTML string
      • 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 file
        remoteFile - 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 send
        remoteFile - 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:
        proxyEval in class Rsession
        Parameters:
        expression - String to evaluate
        vars - 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