This question already has an answer here:
- How do Rpy2, pyrserve and PypeR compare? 4 answers
I am quite new to R, and pretty much used to python. I am not so comfortable writing R code. I am looking for python interface to R, which lets me use R packages in pythonic way.
I have done google research and found few packages which can do that:
But not sure which one is better ? Which has more contributers and more actively used ?
Please note my main requirement is pythonic way for accessing R packages.
My personal experience has been with
Rpy
, notRpy2
. I used it for a while, but dropped it in favor of usingsystem
commands. A typical case for me was running a FORTRAN model using Python scripts, and post-processing with R. In my experience the easiest solution was to create a command line tool using R, which is quite straightforward (at least under Linux). The command line tool could be executed in the root of the model run, and the script would produce a set of R objects and plots in anRoutput
directory. The advantage of disconnecting R and Python in this way was that I could easily debug the R code separate from the Python code.I think
Rpy
really shines when a lot of back and forth communication between R and Python is needed. But if the functionality is nicely separable, and the overhead of disk i/o is not too bad, I would stick tosystem
calls. See?system
for more information regarding system calls, andRscript
for running R scripts as a command line tool.Regarding your wish to write R code in a Python way, this is not possible as all the solutions require you to write R code in R syntax. For
Rpy
this means R syntax, but a little different (no.
for example). I agree with @gauden that there is no shortcut in using R throughRpy
.As pointed out by @lgautier, there is already another answer on this subject. I leave my answer here as it adds the experience of approaching R as a novice, knowing Python first.
I use both Python and R and sympathise with your need as a newcomer to R.
Since any answer you get will be subjective, I summarise a few points from my experience:
My advice:
Once you know both, then you will do magic with rpy2 without the horrors of cross-language debugging.
New Resources
Update on 29 Jan 2015
This answer has proved popular and so I thought it would be useful to point out two more recent resources:
rmagic
inIPython/Jupyter
greatly easing the work of producing reproducible research and notebooks that combine both languages.A question about comparing rpy2, pyrserve, and pyper with each other was answered on the site earlier.
Regarding the number of contributors, I'd say that all 3 have a relatively small number. A site like Ohloh can give a more detailled answer.
How actively a package is used is tricky to determine. One indication might be the number of downloads, an other might be the number of posts on mailing lists or the number questions on a site like stackoverflow, the number of other packages using it or citing it, the number of CVs or job openings mentioning the package. As much as I believe that I could give a fair evaluation, I might also be seen as having a conflict of interest. ;-)
All three have their pros and cons. I'd say that you base you choice on that.