3

Overview: Need to integrate R library with a web server written in python. I have explored some of the options commonly mentioned on different blogs and stack overflow threads. The threads I have come across compare libraries like Rpy2 and pypeR and provide specific answers to integrate R and python. What I am looking for is a general solution so that the R code can be accessed by a multitude of programming languages/clients (for future extensibility).

Requirements:

  1. R code should run separately to handle heavy computation and not be embedded into the application server.
  2. R module should be scalable and easily maintainable. ex- any change to the application server (written in python) should not trigger changes in the R code.
  3. R module can be used as an API for further application development using web frameworks other than python.

Options already explored:

  1. rpy2, pypeR: One option is to write a separate python server and let that server handle R code using rpy2. The app server can send requests to the second server.
  2. Rserve and pyRserve: Use Rserve and pyRserve client to communicate between R and python.
  3. Apache Thrift and Protocol Buffer: rprotobuf is an interface for R to make it work with Protocol Buffer but I could not find any support for R in Apache Thrift. Will something like Thrift or protocol buffer be better than creating an R server.
  4. Rapache and Rook: Use Rapache and Rook package in R to setup a server for processing requests.
  5. deployR: Created by Revolution Analytics.

Which among these would be an ideal choice or any other option which is not in the list?

Andrie
  • 176,377
  • 47
  • 447
  • 496
Ananya Jha
  • 31
  • 3
  • Write an R script and run it using `call`? Any language can do that. – Roman Luštrik Feb 23 '16 at 08:39
  • Modified the first line to clarify the problem. Its not just 1 R script but an entire library that I need to integrate with the web server. And I don't want to call R scripts specifically from the app server. A general solution, which allows me use the library like an API, is required. – Ananya Jha Feb 23 '16 at 08:50
  • If we talk about a *.lib or similar which can be included into C or C++ this would be the way to go. Could that work for your case? If not, why not? "*R code should run separately to handle heavy computation and not be embedded into the application server*" I don't see an issue with having a thin host application around it. – JensG Feb 23 '16 at 09:58

2 Answers2

2

Did you consider the following ?

  • Python has a package to interface with Thrift / create thrift servers.
  • Rpy2 is an interface to R (and arguably the fastest one).

web server <---> Thrift server (Python) (Python + rpy2)

lgautier
  • 11,363
  • 29
  • 42
0

Regarding Apache Thrift bindings:

  • First, Apache Thrift does not have native bindings for R1).

  • Second, from what I read so far (I am not an R user), there are plenty of options to integrate R into other host languages. Thrift offers support for C++, C, Java, Python and a plethora of other targets and languages, 20+ in total. So it seems possible to create a host application offering the Thrift API and housing the R stuff.


1) Today. I can't look into the future, and things change quickly sometimes.

JensG
  • 13,148
  • 4
  • 45
  • 55
  • Will creating a host application housing R and then using Thrift to connect it to other languages scale up? Also is there any specific benefit of using this kind of a setup over the others? Protocol Buffer has an interface for R. How does Protocol Buffer compare against Apache Thrift? – Ananya Jha Feb 24 '16 at 13:37