Package org.math.R

Class StartRserve


  • public class StartRserve
    extends Object
    simple class that start Rserve locally if it's not running already - see mainly checkLocalRserve method. It spits out quite some debugging outout of the console, so feel free to modify it for your application if desired.

    Important: All applications should shutdown every Rserve that they started! Never leave Rserve running if you started it after your application quits since it may pose a security risk. Inform the user if you started an Rserve instance.

    • Field Detail

      • TIMEOUT

        public static long TIMEOUT
    • Constructor Detail

      • StartRserve

        public StartRserve()
    • Method Detail

      • isRserveInstalled

        public static boolean isRserveInstalled()
                                         throws IOException
        R batch to check Rserve is installed in RserveDaemon.app_dir()
        Returns:
        Rserve is already installed
        Throws:
        IOException
      • installRserve

        public static boolean installRserve​(String Rcmd,
                                            String http_proxy,
                                            String repository)
                                     throws IOException
        R batch to install Rserve from net
        Parameters:
        Rcmd - command necessary to start R
        http_proxy - http://login:password@proxy:port string to enable internet access to rforge server
        repository - from which R repo ?
        Returns:
        success
        Throws:
        IOException
      • doInR

        public static String doInR​(String todo,
                                   String Rcmd,
                                   String rargs,
                                   File out)
                            throws IOException
        attempt to start Rserve. Note: parameters are not quoted, so avoid using any quotes in arguments
        Parameters:
        todo - command to execute in R
        Rcmd - command necessary to start R
        rargs - arguments are are to be passed to R (e.g. --vanilla -q)
        out - file to redirect R output. If null set a default name.
        Returns:
        true if Rserve is running or was successfully started, false otherwise.
        Throws:
        IOException
      • system

        public static Process system​(String command,
                                     File redirect,
                                     boolean waitFor)
      • KillAll

        public static boolean KillAll​(String taskname)
      • Kill

        public static boolean Kill​(int pid)
      • launchRserve

        public static StartRserve.ProcessToKill launchRserve​(String Rcmd,
                                                             String rargs,
                                                             String rsrvargs,
                                                             boolean debug,
                                                             ServerSocket lock)
                                                      throws IOException
        attempt to start Rserve.Note: parameters are not quoted, so avoid using any quotes in arguments
        Parameters:
        Rcmd - command necessary to start R
        rargs - arguments are are to be passed to R
        rsrvargs - arguments to be passed to Rserve
        debug - Rserve debug mode ?
        lock - ServerSocket locker. Should be closed before using Rserve
        Returns:
        true if Rserve is running or was successfully started, false otherwise.
        Throws:
        IOException
      • getRservePIDs

        public static int[] getRservePIDs()
      • checkLocalRserve

        public static boolean checkLocalRserve​(int port)
        checks whether Rserve is running and if that's not the case it attempts to start it using the defaults for the platform where it is run on.This method is meant to be set-and-forget and cover most default setups. For special setups you may get more control over R with launchRserve instead.
        Parameters:
        port - Rserve port to check
        Returns:
        is ok ?
      • isRserveListening

        public static boolean isRserveListening​(int port)
        check whether Rserve is currently running (on local machine and default port).
        Parameters:
        port - Rserve port to check
        Returns:
        true if local Rserve instance is running, false otherwise
      • main

        public static void main​(String[] args)
        just a demo main method which starts Rserve and shuts it down again
        Parameters:
        args - ...