de.jstacs.utils
Class RUtils

java.lang.Object
  extended by de.jstacs.utils.RUtils

public class RUtils
extends Object

This is a collection of various silly things you can do when accessing Rserve.

This class is based on an implementation of Andreas Stephanik and was further developed by Jens Keilwagen.

Author:
Andreas Stephanik, Jens Keilwagen
See Also:
REnvironment

Constructor Summary
RUtils()
           
 
Method Summary
static int copyFileFromServer(String sourcePath, OutputStream out, RConnection c)
          Pipes a RFileInputStream of the given sourcePath into the given OutputStream out
static int copyFileFromServer(String sourcePath, String targetPath, RConnection c)
          This method copies a file from the server to the client.
static void copyFileToServer(File source, String targetName, RConnection rconnection)
          Copies a file to the R side.
static void copyFileToServer(String sourcePath, String targetName, RConnection rconnection)
          Copies a file to the R side.
static void installRScript(String sourcePath, String targetName, RConnection rconnection)
          Installs an R script on the Rserve server.
static RConnection openRConnection(String rServeHostName, String loginName, String passwd)
          This method opens an RConnection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RUtils

public RUtils()
Method Detail

installRScript

public static void installRScript(String sourcePath,
                                  String targetName,
                                  RConnection rconnection)
                           throws Exception
Installs an R script on the Rserve server. Do not forget to remove the R script by RConnection.removeFile(String targetname) at the end of your session.

Parameters:
sourcePath - path of your R script on your local box, this script will be copied to the Rserve server (e.g. pdw-24 /tmp/Rserve/conn*)
targetName - just the desired name of the R script on the Rserve server (mostly the same as on local box, but without path delimiters!), should not contain any path delimiters, since Rserve may restrict the access to local working directory
rconnection - an already open connection to the Rserve server
Throws:
Exception - if something went wrong while installing the R script on the Rserve server

copyFileToServer

public static void copyFileToServer(File source,
                                    String targetName,
                                    RConnection rconnection)
                             throws Exception
Copies a file to the R side. Normally it is send to /tmp/Rserve/conn* .

Parameters:
source - the source file
targetName - should not contain any path delimiters, since Rserve may restrict the access to local working directory
rconnection - the connection to R
Throws:
Exception - if something went wrong while copying the file

copyFileToServer

public static void copyFileToServer(String sourcePath,
                                    String targetName,
                                    RConnection rconnection)
                             throws Exception
Copies a file to the R side. Normally it is send to /tmp/Rserve/conn* .

Parameters:
sourcePath - the source path
targetName - should not contain any path delimiters, since Rserve may restrict the access to local working directory
rconnection - the connection to R
Throws:
Exception - if something went wrong while copying the file
See Also:
copyFileToServer(File, String, RConnection)

copyFileFromServer

public static int copyFileFromServer(String sourcePath,
                                     String targetPath,
                                     RConnection c)
                              throws IOException
This method copies a file from the server to the client.

Parameters:
sourcePath - the server path name
targetPath - the client path name
c - the connection to R
Returns:
the number of copied bytes
Throws:
IOException - if the file could not be copied

copyFileFromServer

public static int copyFileFromServer(String sourcePath,
                                     OutputStream out,
                                     RConnection c)
                              throws IOException
Pipes a RFileInputStream of the given sourcePath into the given OutputStream out

Parameters:
sourcePath - the server path name
out - the stream which is used to write the content
c - the connection to R
Returns:
the number of copied bytes
Throws:
IOException - if the file could not be copied

openRConnection

public static RConnection openRConnection(String rServeHostName,
                                          String loginName,
                                          String passwd)
                                   throws Exception
This method opens an RConnection.

Parameters:
rServeHostName - the name of the server with RServe
loginName - the login (if needed)
passwd - the password (if needed)
Returns:
a connection to R
Throws:
Exception - if no connection could be established