Rserve documentation. URL: http://stats.math.uni-augsburg.de/Rserve/

Documentation for Rserve


Introduction
         Rserve itself is the server, that is a program that responds to requests from clients. It listens for any incoming connections and processes incoming requests. You need to have R-1.5.0 or higher installed on your system in order to be able to use Rserve. For details concerning installation and start of the server, see Installation futher down.

The server is nothing without clients, therefore we have developed three client frameworks:

  • JRclient - a full client suite that allows any Java application (JDK 1.1 or higher) to access an Rserve. The suite is written entirely in Java. It provides automatic type translation for most objects such as int,double,arrays,String or Vector and classes for special R objects such as RBool, RList etc. For sample code and a small tutorial see Examples. JavaDoc documentation of JRclient-classes is available online here.
     
  • C++ client - it is located in src/client directory in the Rserve source package and provides basic interface to Rserve from any C++ program.
     
  • Rcli.c - a lightweight client that demonstrates how to connect to Rserve from C language. It does not go beyound a proof of concept, because R provides C API, so there is usually no need for a C client. (It is available in early Rserve versions, now replaced by the C++ client).
It is basically possible to write clients for any language that supports TCP/IP sockets. The separation of client/serve side allows to prevent multi-threading problems that arise when linking against R library directly.
Installation
The easiest way to install Rserve is to use a source package for R. Please note that this works only for unix-based operating systems such as Linux, Solaris, AIX or Mac OS X. (There is currently a binary version available for Windows, see below.) Download the package file Rserve_0.4-3.tar.gz in the current directory. Login with enough privileges to add R packages and run:

R CMD INSTALL Rserve_0.4-3.tar.gz

This should compile and install Rserve. You can check whether Rserve is installed correctly by looking in the $RHOME/bin directory - there should be a file called Rserve.

If the compilation fails, please check that R shared library exists and is properly installed. It is located in $RHOME/bin and is named libR.so or libR.dylib. If it is missing, get an R distribution with shared library included or compile R with --enable-R-shlib configure flag.

Windows: There is a binary version of Rserve in the download section. Copy the file to the directory containing R.DLL. If you have more versions of R, make sure that you use the one most recently installed, becasue Rserve detects the location of $RHOME from the registry. Although Rserve works on Windows it is not recommended to use it on that platform. Windows lacks important features that make the separation of namespaces possible, therefore Rserve for Windows works in cooperative mode only, that is only one connection at a time is allowed and all subsequent connections share the same namespace. Briefly: don't use Windows unless you really have to. There is a DCOM interface available for R, you may be better off with that solution.

Launching Rserve
Rserve is not really a package, therefore it is not used via library command, instead it is a program on its own. To start Rserve, run:

R CMD Rserve

Depending on the purpose and libraries on your computer you may want to add --gui-none. Rserve passes any parameters to the underlying R engine except for Rserver-related parameters (see command line arguments). After initialization Rserve daemonizes itself to work as a server. It can be shut down gracefully (i.e. it will wait until all existing connections are finished) if it recieves shutdown command from an authorized connection. It terminates not so gracefully if it receives usual termination signals.

If no config file is supplied, Rserve accepts no remote connections, requires no authentication and file transfer is enabled. For more details about how to configure Rserve, see below.

Configuration
Rserve is configured by the configuration file /etc/Rserv.conf (can be changed at compile time by specifying -DCONFIG_FILE=..). Additional configuration files can be added by the --RS-conf command line argument. The possible configuration entries are as follows (all entries are optional; default values are in angled brackets):

workdir <path> [/tmp/Rserv]
pwdfile <file> [none=disabled]
remote enable|disable [disable]
auth required|disable [disable]
plaintext enable|disable [disable] (strongly discouraged to enable)
fileio enable|disable [enable]

(since version 0.1-9):
socket <socket> [none=disabled]
port <port> [6311]
maxinbuf <size in kb> [262144]

(since version 0.3:)
maxsendbuf <size in kb> [0=unlimited]
uid <uid> [none]
gid <gid> [none]

(since version 0.3-16:)
source <file>
eval <expressions>

Most entries are self-explaining and their command line equivalents are described below. maxinbuf and maxsendbuf are rather special. Previous versions of Rserve had fixed buffer sizes. Since 0.1-9 internal buffers change per-connection automatically. The maxinbuf specifies (in kilobytes) the maximal allowable size of the input buffer, that is the maximal size of data transported from the client to the server. Analogously maxsendbuf sets the maximum size of the send buffer, that is the size of data sent from Rserve to the client. If your server is likely to process very many parallel connections you may want to lower this setting for security reasons. On the other hand if the server will process only few connections in parallel and you expect very large data, raise the value accorsing to your computer's memory. Baiscally the settings are present to prevent malicious users from crashing your server by supplying too large data. 0 has a special meaning telling Rserve to allow unlimited use.

uid and gid are supported on unix computers only. If Rserve is run as root user, then it switches the user/group to the specified uid/gid before starting the server. Note: The directives are processed in the same sequence in which they occur in the config file. This implies that if using both uid and gid, you MUST use gid first, otherwise if setting uid first, then the user will have no right to change gid anymore!

A note about security: Anyone with access to R has access to the shell via "system" command, so you should consider following rules:

  • NEVER EVER run Rserv as root (unless uid/gid entries are set) - this compromises the box totally
  • Use "remote disable" whenever you don't need remote access.
  • If you need remote access use "auth required" and "plaintext disable". Consider also that anyone with the access can decipher other's passwords if he knows how to. The authentication prevents hackers from the net to break into Rserve, but it doesn't (and cannot) protect from inside attacks (since R has no security measures). You should also use a special, restricted user for running Rserv as a public server, so noone can try to hack the box it runs on.
  • don't enable plaintext unless you really have to. Passing passwords in plain text over the net is not wise and not necessary since both Rserv and JRclient provide encrypted passwords with server-side challenge (thus safe from sniffing).
Command line arguments
Starting with Rserve 0.1-9 special command line arguments are supported in addition to the config file. Normally Rserve passes all arguments to R, but several special ones are processed and removed from the list before initializing R. Those parameters override any settings specified in the config file.
--RS-port portRserve will listen on the specified TCP port.
--RS-socket socketuse the specified local unix socket instead of TCP/IP.
--RS-workdir pathset working directory root for connections to the specified path.
--RS-conf fileload the specified config file (the default config file is still loaded, but its settings have lower priority).
--RS-dumplimit n(debug version of Rserve only) specifies the number of values to print when dumping content of packages or SEXPs (default is 128).
--RS-settingsprint current settings of the Rserve. Useful to check the current configuration.
--helpprints a brief help screen and exits (R is not started)
--versionprints version of Rserve. This argument is retained in the list and processed by R as well.
In order to list all currently supported arguments, type:
R CMD Rserve --help

Last updated: [an error occurred while processing the directive] (C)Copyright 2003 Simon Urbanek (
simon.urbanek@math.uni-augsburg.de)