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.

Installation

The package can be installed via

install.packages("rPython", repos = "http://www.datanalytics.com/R")

as source package. This approach should work on Linux and other UNIX-like platforms, such as Mac, but would fail on Windows. In fact, so far, the author has been unable to find a reliable way to locate the required Python files on a Windows platform.

Help in this regard would be highly appreciated.

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.