RServe – Introduction and Installation

Related Tutorials

First Sample Program

Introduction

RServe is an R package that allows other applications to talk to R using TCP/IP. It creates a socket server to which other applications can connect. RServe provides client implementation for common languages such as C/C++, Java and PHP. In this series of tutorials we will look at how to use java to make calls to R using RServe. Features of RServe are ::

  • RServe can be started without starting R. There is no need to initialize R or link to the R libraries
  • The java client is present in src/client/java-new
  • The default port for RServe is 6311
  • The R objects are transferred as binary object between the server and the client. Files can be transferred between the client and the server
  • Each connection has its own working directory and namespace.
  • The client converts R objects to java objects. The java client has classes such as RBool, RList etc.
  • multiple connections can access RServe in thread-safe manner. However, multiple eval calls using the same connection are not thread safe.

Platform – Windows of linux?

RServe can be installed on both windows and linux platform, however it is recommended to install and use it on a linux platform. To use R with java on a single windows machine it would be better to use the native client JRI instead. The RJava Eclipse Plugin can be used to set up JRI for use within a single windows machine. However, if you are looking for an enterprise level solution that supports multi-threading then RServe is a better choice.

Installation and Starting RServe

Installing RServe is very simple. Start R and on the command prompt type in install.packages(“RServe”,dest=”&ltDEST_DIR&gt”). The DEST_DIR stores the RServe source package. We will need this to get the java client. This will download and install RServe.

RServe can be started in two ways

    • Directly from R. On the R console type library(“Rserve”). This will load RServe
    • On the console type Rserve(). This will start RServe in daemon mode. Note that R does not have to be running in order to use RServe. You can quit the R console and RServe will still run.
    • Since RServe runs as a daemon, you can shut it down gracefully from the client (we shall see that later). However, to explicitly kill RServe on a linux box, type in ps -ef | grep Rserve. Look for the RServe process. you should see something like &ltR_HOME&gtRserve/libs//Rserve-bin.so. Note down the process id and kill the process using kill -9 process_id
  1. From the unix console. Start RServe using the command R CMD RServe. This will again start RServe as a daemon.

2 thoughts on “RServe – Introduction and Installation”

Leave a Comment