A simple and efficient access to R from Python |
|
A Demonstration of RPy: Tim ChurchesRPy, written by Walter Moreira and maintained by Gregory Warnes, is a Python extension module for using the R programming environment for data analysis and graphics from within Python. RPy is available from the RPy project web page. As Walter notes, RPy was inspired by RSPython by Duncan Temple Lang. RSPython allows R to be called from Python and vice-versa (i.e. Python can be embedded in R), as well as providing more general facilities for exploiting the object-oriented aspects of both Python and R. However, at least for me, RPy is a lot easier to use. It is my sincere hope that RPy and RSPython can be merged in a display of el Norte/el Sur co-operation, so we can have the best of both. The following example provides a small taste of both the power of the R environment and the ease with which RPy allows this power to be used from within Python. The data are eruption times for the Old Faithful geyser which, along with Yogi Bear, is located in the Yellowstone National Park in Wyoming, USA. The data file faithful.dat was exported from the faithful example dataset which comes as part of R. The R code in this example was borrowed directly from Section 8.2 of "An Introduction to R, Version 1.4.1" by W.N. Venables, D.M. Smith and the R Development Core Team. Minimal changes to the orginal R code were required to make it work from within Python, thanks to RPy. The following Python code (faithful.py):
produces the following output:
and these graphs:
Impressed? I was. Cheers, |
|