R-Forge Logo

rPython R package

This package allows the user to call Python from R. It is a natural extension of the rJython package by the same author.

What can be done with it?

rPython is intended for running Python code from R. R programs and packages can:

Here is a sample session with rPython:

python.call( "len", 1:3 )
a <- 1:4
b <- 5:8
python.exec( "def concat(a,b): return a+b" )
python.call( "concat", a, b)

python.assign( "a",  "hola hola" )
python.method.call( "a", "split", " " )

Who may be interested in it?

Mainly, users and package developers who want to use functionalities available in Python but not in R.

There are many modules in Python which could easily extend R functionality if there would be a way to call Python code from R.

How does this package relate to rpy and rpy2?

rpy and rpy2, a redesign and rewrite of rpy, are Python interfaces to R. They allow users to call R from Python.

rPython provides the opposite interface.

Besides, no code from rpy/rpy2 has been used in the development of rPython.

How does rPython work?

One of the most daunting tasks in building an interface between two languages is provide mechanisms for exchanging different data structures between them. rPython uses json:

  1. R/Python objects are dumped into json strings using their respective parsers (RJSONIO and simplejson) respectively.
  2. These strings are passed between the two languages using their string exchange mechanisms.
  3. json strings are finally reconstructed into language objects on the other side.

This simple mechanism allow R and Python exchange relatively complex data structures with ease.


The package can be installed from CRAN:


This should on Linux and other UNIX-like platforms, such as Mac, but would fail on Windows. Windows users may want to check rPython-win.

Some users want to use rPython using ad hoc Python installations (e.g., Anaconda) or in virtualenvs. It often fails.

Also, it is possible to install rPython to use it on a system installation different from the default one (e.g., Python 3.2 on a system where the default installation is 2.7). It is possible to do so: read the INSTALLATION file contained within the package.

Further info

The project summary page can be found here.

The package has been developed by Carlos J. Gil Bellosta and is based on a previous package, rJython, by the same author together with G. Grothendieck.