Take the 2-minute tour ×

I would like to access R from within a Python program. I am aware of Rpy2, pyrserve and PypeR.

What are the advantages or disadvantages of these three options?

share|improve this question
Duplicate of stackoverflow.com/questions/2573132/… –  Andreas Jung Apr 12 '11 at 4:34
Actually, the question is NOT a dublicate, however the answer to the Python 3.1.1 question does answer the OP's question. –  Michael Dillon Apr 12 '11 at 6:09
On second thought, this is not a duplicate at all. pyrserve and PypeR are not discussed in the other question, so I'll vote to reopen if it gets closed. Good question! –  Joris Meys Apr 12 '11 at 9:31
There is no comparison of these packages at that link. Only a mention that they exist (and that Rpy2 was incompatible with Python 3.x when the question was asked, but it is compatible now). –  DanB Apr 12 '11 at 12:34
As of November 2012, I think the community has settled on rpy2 (and the r magic in ipython.) My personal experience with rpy2 has been very positive. –  DanB Nov 30 '12 at 23:20

3 Answers 3

up vote 20 down vote accepted

I know one of the 3 better than the others, but in the order given in the question:


  • C-level interface between Python and R (R running as an embedded process)
  • R objects exposed to Python without the need to copy the data over
  • Conversely, Python's numpy arrays can be exposed to R without making a copy
  • Low-level interface (close to the R C-API) and high-level interface (for convenience)
  • In-place modification for vectors and arrays possible
  • R callback functions can be implemented in Python
  • Possible to have anonymous R objects with a Python label
  • Python pickling possible
  • Full customization of R's behavior with its console (so possible to implement a full R GUI)
  • MSWindows with limited support


  • native Python code (will/should/may work with CPython, Jython, IronPython)
  • use R's Rserve
  • advantages and inconveniences linked to remote computation and to RServe


  • use of pipes to have Python communicate with R (with the advantages and inconveniences linked to it)

edit: Windows support for rpy2

share|improve this answer

From the paper in the Journal of Statistical Software on PypeR:

RPy presents a simple and efficient way of accessing R from Python. It is robust and very convenient for frequent interaction operations between Python and R. This package allows Python programs to pass Python objects of basic data types to R functions and return the results in Python objects. Such features make it an attractive solution for the cases in which Python and R interact frequently. However, there are still limitations of this package as listed below.
RPy may not behave very well for large-size data sets or for computation-intensive duties. A lot of time and memory are inevitably consumed in producing the Python copy of the R data because in every round of a conversation RPy converts the returned value of an R expression into a Python object of basic types or NumPy array. RPy2, a recently developed branch of RPy, uses Python objects to refer to R objects instead of copying them back into Python objects. This strategy avoids frequent data conversions and improves speed. However, memory consumption remains a problem. [...] When we were implementing WebArray (Xia et al. 2005), an online platform for microarray data analysis, a job consumed roughly one quarter more computational time if running R through RPy instead of through R's command-line user interface. Therefore, we decided to run R in Python through pipes in subsequent developments, e.g., WebArrayDB (Xia et al. 2009), which retained the same performance as achieved when running R independently. We do not know the exact reason for such a difference in performance, but we noticed that RPy directly uses the shared library of R to run R scripts. In contrast, running R through pipes means running the R interpreter directly.
R has been denounced for its uneconomical use of memory. The memory used by large- size R objects is rarely released after these objects are deleted. Sometimes the only way to release memory from R is to quit R. RPy module wraps R in a Python object. However, the R library will stay in memory even if the Python object is deleted. In other words, memory used by R cannot be released until the host Python script is terminated.
As a module with extensions written in C, the RPy source package has to be compiled with a specific R version on POSIX (Portable Operating System Interface for Unix) systems, and the R must be compiled with the shared library enabled. Also, the binary distributions for Windows are bound to specic combinations of different versions of Python/R, so it is quite frequent that a user has difficulty in finding a distribution that ts the user's software environment.

share|improve this answer
Not sure that this is an unbiased comparison. May be I'll bias it the other way around to balance then ;-). Beside a possible confusion between rpy and rpy2 (the name changes throughout the text), the implementation specificity (C vs pure R) appears to me the only valid point.The alleged issue with memory usage results of failing to call garbage collection explicitly (something known to happen with Python). There are plenty of examples were pyper can be shown to be both consuming more memory (by design) and orders of magnitude slower. –  lgautier Apr 12 '11 at 19:57
@Igautier -- Do you have any links to examples where Rpy2 is significantly faster or more memory efficient than pyper? –  DanB Apr 12 '11 at 21:33
@DanB -- any example involving numpy computation and R computation using the same vector/array/matrix is required... almost any example where an object is accessed and modified by both R and Python actually –  lgautier Apr 13 '11 at 10:35

in pyper, i can't pass large matrix from python to r instance with assign(). however, i don't have issue with rpy2. it is just my experience.

share|improve this answer
I am having problems with pyper too when passing large matrices from Python to R. The data seems to "go through" but the R computations I do crash randomly. I wonder if there is a bug or a limitation in what pyper can handle. –  user815423426 Feb 10 '13 at 4:08

Your Answer


