Class RCaller


  • public class RCaller
    extends Object
    Author:
    Mehmet Hakan Satman mhsatman@yahoo.com http://stdioe.blogspot.com http://www.mhsatman.com http://code.google.com/p/rcaller
    • Method Detail

      • create

        public static RCaller create()
        Static factory creator for the default object
        Returns:
        default RCaller object
      • create

        public static RCaller create​(RCallerOptions rCallerOptions)
        Static factory creator with startup options
        Parameters:
        rCallerOptions - given startup options
        Returns:
        RCaller object
      • create

        public static RCaller create​(RCode rcode,
                                     RCallerOptions rCallerOptions)
        Static factory creator with given R code and startup options
        Parameters:
        rcode - RCode object that contains R code that will be run at the startup
        rCallerOptions - given startup object
        Returns:
        RCaller object
      • stopStreamConsumers

        public boolean stopStreamConsumers()
        Stops the threads that are emptying the output and error streams of the live but idle R process. If R is still working, this may cause it to hang. If R has finished execution, these threads prevent the operating system from shutting it down, so that the same process is used. Invoke this method when you have used R online and are finished with it.
        Returns:
        true if rOutput and rError are alive, else return false
      • startStreamConsumers

        public void startStreamConsumers​(Process process)
      • getCranRepos

        public String getCranRepos()
        Returns:
        The default Cran repository
      • getRCode

        public RCode getRCode()
      • setRCode

        public void setRCode​(RCode rcode)
      • setGraphicsTheme

        public void setGraphicsTheme​(GraphicsTheme theme)
      • deleteTempFiles

        public void deleteTempFiles()
        RCaller uses temp directory for many cases. This sometimes causes inflations of number of temporary files. This method deletes the file created by RCaller in temp directory.
      • runOnly

        public void runOnly()
                     throws ExecutionException
        Executes the code contained in this RCaller instance in s separate process. Upon completion the process is killed and none of the R variables are returned
        Throws:
        ExecutionException - if R cannot be run for some reason
      • runAndReturnResultOnline

        public void runAndReturnResultOnline​(String var)
                                      throws ExecutionException
        Runs the current code in the existing R instance (or in a new one) and returns the R variable "var". The R process is kept alive and can be re-used by invoking this method again. When you are done with this process, you must explicitly stop it. If R raises an error, it is ignored. For throwing them in Java, use runAndReturnResultOnline(String, boolean) with addTryCatch=true
        Parameters:
        var - The R variable to return
        Throws:
        ExecutionException - if R cannot be started
        See Also:
        stopStreamConsumers()
      • runAndReturnResultOnline

        public void runAndReturnResultOnline​(String var,
                                             boolean addTryCatch)
                                      throws ExecutionException
        Runs the current code in the existing R instance (or in a new one) and returns the R variable "var". The R process is kept alive and can be re-used by invoking this method again. When you are done with this process, you must explicitly stop it.
        Parameters:
        var - The R variable to return
        addTryCatch - wrap original R code to tryCatch function (can impact performance)
        Throws:
        ExecutionException - if R cannot be started or raise error inside while addTryCatch parameter is true
        Since:
        4.0.0
        See Also:
        stopStreamConsumers()
      • StopRCallerOnline

        @Deprecated
        public void StopRCallerOnline()
        Deprecated.
        Stops underlying R process gracefully. No calculations should be running.
      • stopRCallerOnline

        public void stopRCallerOnline()
        Stops underlying R process gracefully. No calculations should be running.
      • StopRCallerAsync

        @Deprecated
        public void StopRCallerAsync()
        Deprecated.
        Stops underlying R process anyway. May be used from separate thread to terminate running calculations.
      • stopRCallerAsync

        public void stopRCallerAsync()
        Stops underlying R process anyway. May be used from separate thread to terminate running calculations.
      • runAndReturnResult

        public void runAndReturnResult​(String var)
                                throws ExecutionException
        Runs the current code and returns the R variable "var". The R process is terminated upon completion of this method.
        Parameters:
        var - the R variable to return
        Throws:
        ExecutionException - if R could be started; if a temporary file to store the results could not be created; if the temporary file is corrupt. The exact cause will be added to the stack trace
      • redirectROutputToStream

        public void redirectROutputToStream​(OutputStream o)