RServe – Introduction and Installation
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Related Tutorials
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=”<DEST_DIR>”). 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 <R_HOME>Rserve/libs//Rserve-bin.so. Note down the process id and kill the process using kill -9 process_id
- From the unix console. Start RServe using the command R CMD RServe. This will again start RServe as a daemon.
The post RServe – Introduction and Installation appeared first on StudyTrails.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.