R编程语言的Python接口 [英] Python interface for R Programming Language

查看:190
本文介绍了R编程语言的Python接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对R相当陌生,并且几乎习惯了python.我不太喜欢编写R代码.我正在寻找R的python接口,该接口允许我以 pythonic方式使用R包.

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.

我已经完成了google研究,并发现了一些可以做到这一点的软件包:

I have done google research and found few packages which can do that:

  • Rpy2
  • PypeR
  • pyRserve

但是不确定哪个更好?哪个贡献者更多且使用更积极?

But not sure which one is better ? Which has more contributers and more actively used ?

请注意,我的主要要求是访问R包的Python方式.

Please note my main requirement is pythonic way for accessing R packages.

推荐答案

@lgautier指出,已经有这个主题.我在这里留下我的答案,因为它增加了将R作为新手的经验,首先了解Python.

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.

我同时使用Python和R,并同情您作为R的新手的需求.

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:

  • 我使用 rpy2 作为界面,发现它是"Pythonic"的,稳定的,可预测的且有效的足以满足我的需求.我没有使用其他软件包,因此这不是对它们的评论,而是对rpy2本身的优点的评论.
  • 但是,不要期望在不学习两者的情况下,会有在Python中使用R的简便方法.我发现在两种语言之间都添加接口可以简化编码,但同时又会给缺少一种语言的人带来调试的噩梦.
  • I use rpy2 as my interface and find it is 'Pythonic', stable, predictable, and effective enough for my needs. I have not used the other packages so this is not a comment on them, rather on the merits of rpy2 itself.
  • BUT do not expect that there will be an easy way of using R in Python without learning both. I find that adding an interface between the two languages allows ease of coding when you know both, but a nightmare of debugging for someone who is deficient in one of the languages.

我的建议:

  1. 对于大多数应用程序,Python提供了一些程序包,这些程序包使您可以执行R要做的大部分事情,从数据整理到绘图.查看 SciPy pandas matplotlib 和其他科学方法软件包,甚至完整的 Anaconda RStudio Quick-R Learn-R 让我进展很快.
  1. For most applications, Python has packages that allow you to do most of the things that you want to do in R, from data wrangling to plotting. Check out SciPy, NumPy, pandas, BioPython, matplotlib and other scientific packages, or even the full Anaconda or Enthought python distributions. This allows you to stay within the Python environment and provides you most of the power that you need.
  2. At the same time, you will want R's vast range of specialised packages, so spend some time learning it in an interactive environment. I found it almost impossible to master even basic R on the command line, but RStudio and the tutorials at Quick-R and Learn-R got me going very fast.

一旦您知道两者,那么您将使用 rpy2 做魔术,而不必担心跨语言调试

Once you know both, then you will do magic with rpy2 without the horrors of cross-language debugging.

2015年1月29日更新

事实证明,这个答案很受欢迎,因此我认为指出最近的两个资源会很有用:

This answer has proved popular and so I thought it would be useful to point out two more recent resources:

  • Ralph Heinkel gave a great talk on this subject at EuroPython 2014. The video on Combining the powerful worlds of Python and R is available on the EuroPython YouTube channel. Quoting him:

三元组 R

The triplet R, Rserve, and pyRserve allows the building up of a network bridge from Python to R: Now R-functions can be called from Python as if they were implemented in Python, and even complete R scripts can be executed through this connection.

  • 现在可以使用 rmagic组合R和Python在IPython/Jupyter 中极大地简化了将两种语言结合在一起的可重复研究和笔记本的制作工作.
    • It is now possible to combine R and Python using rmagic in IPython/Jupyter greatly easing the work of producing reproducible research and notebooks that combine both languages.
    • 这篇关于R编程语言的Python接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆