[R] Python and R

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Feb 18 00:05:40 CET 2009


2009/2/17 Esmail Bonakdarian <esmail.js at gmail.com>:
> Hello all,
>
> I am just wondering if any of you are doing most of your scripting
> with Python instead of R's programming language and then calling
> the relevant R functions as needed?

 I tend to use R in its native form for data analysis and modelling,
and python for all my other programming needs (gui stuff with PyQt4,
web stuff, text processing etc etc).

> And if so, what is your experience with this and what sort of
> software/library  do you use in combination with Python to be able
> to access R's functionality.

 When I need to use the two together, it's easiest with 'rpy'. This
lets you call R functions from python, so you can do:

 from rpy import r
 r.hist(z)

to get a histogram of the values in a python list 'z'. There are some
complications converting structured data types between the two but
they can be overcome, and apparently are handled better with the next
generation Rpy2 (which I've not got into yet). Google for rpy for
info.

> Is there much of a performance hit either way? (as both are interpreted
> languages)

 Not sure what you mean here. Do you mean is:

 R> sum(x)

faster than

Python> sum(x)

and how much worse is:

Python> from rpy import r
Python> r.sum(x)

?

 Knuth's remark on premature optimization applies, as ever....

Barry




More information about the R-help mailing list