Embedding R in CPP--Calling R functions from C++

207 views
Skip to first unread message

Shekhar

unread,
Dec 28, 2011, 7:33:08 AM12/28/11
to Bangalore R Users - BRU
Hi,
Embedding C/C++ in R seems to be very easy using Rcpp package, but
calling R functions from C++ requires lot of linkage and i felt it is
not that easy and i have not yet successfully done this.

Rserve package does this integeration in a very easy manner, through
socket communication mechanism. Rserve act as a server which accepts
requests from the client either remotely or on the same machine,
evaluate the R expression and sends back the result to the client.
I have done the integration on CentOS 64 bit machine. To install
Rserve, you need to build the R from source with --enable-R-shlib
switch.

You can refer http://groups.google.com/group/brumail/browse_thread/thread/39e32c7df63bc5c1
post to build R from source.

For installing Rserve you need to do following things.

Step 1:
export CFLAGS=-fPIC
export CXXFLAGS=-fPIC

Step2:
I am assumming you are following my post to build R from source. in
that case you need to run the following command

./configure --with-x=no --enable-R-shlib=yes
make

Step 3: Once build is fine and completed, copy libR.so from $R_HOME/
lib to /usr/local/lib64/R/lib

Step 4: Open R console and run install.package("Rserve")

once installation is done, from the R console run Rserve(), this
command will start Rserve service and now you are ready to call R
functions from c++ program.

Rserve comes with sample clients for c++, java etc. In order to get
the sample clients code, you can download the tar file of Rserve.
wget http://cran.r-project.org/src/contrib/Rserve_0.6-6.tar.gz

Regards,
Som Shekhar
Reply all
Reply to author
Forward
0 new messages