Python 和 Rpy2:使用带有“.”的选项调用绘图函数在他们之中
我刚刚开始学习如何将 rpy2 与 python 一起使用。我能够制作简单的绘图等,但我遇到了 R 中许多选项使用“.”的问题。例如,这是一个有效的 R 调用:
条形图(t,col=heat.colors(2),names.arg=c(“pwn”,“pwn2”))
其中 t 是矩阵。
我想在 python 中使用相同的调用,但它拒绝“。”名称.arg 的一部分。我的理解是,在Python中你替换“。”与“_”,例如名称_arg,但这也不起作用。我知道这是一个基本问题,所以我希望有人看到这个并知道解决方法。谢谢!
I'm just starting to learn how to use rpy2 with python. I'm able to make simple plots and such, but I've run into the problem that many options in R use ".". For example, here's an R call that works:
barplot(t, col=heat.colors(2), names.arg=c("pwn", "pwn2"))
where t is a matrix.
I want to use the same call in python, but it rejects the "." part of names.arg. My understanding was that in python you replace the "." with "_", so names_arg for example, but that is not working either. I know this is a basic problem so I hope someone has seen this and knows the fix. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在此处使用字典作为命名参数(使用 **)如文档中的描述,并直接调用 R 函数。另请记住,RPy2 需要自己的矢量对象。是的,这有点尴尬,但从好的方面来说,您应该能够在 rpy2 中执行在 R 中可以执行的任何操作。
(请注意,这是针对 rpy2 版本 2.0.x;未发布的 2.1 我还没有机会查看。)
You can use a dictionary here for the named arguments (using **) as described in the docs, and call R directly for the functions. Also remember that RPy2 expects its own vector objects. Yes, it's a bit awkward, but on the plus side, you should be able to do anything in rpy2 you could do in R.
(Note that this is for rpy2 version 2.0.x; there are some changes in the unreleased 2.1 which I haven't had a chance to look at yet.)
我不知道 Rpy 是否会接受这一点,但是您可以使用带有句点的关键字参数。不过,你必须通过字典传递它们。像这样:
I don't know whether Rpy will accept this, but you can have keyword parameters with periods in them. You have to pass them through a dictionary though. Like this:
对于 rpy2-2.1.0,一种编写方法是:
必须使用 barplot_default (而不是 barplot)是由于
R 函数签名中广泛使用省略号“...”
事实上,保存参数名称翻译需要
分析函数包含的 R 代码。
更多,以及执行系统翻译的功能示例
的 '。'到“_”的位置是:
http://rpy.sourceforge.net/rpy2/doc- 2.1/html/robjects.html#functions
With rpy2-2.1.0, one way to write it would be:
Having to use barplot_default (rather that barplot) is due to the
extensive use of the ellipsis '...' in R'sfunction signatures and
to the fact that save parameter name translation would require
analysis of the R code a function contains.
More, and an example of a function to perform systematic translation
of '.' to '_' is at:
http://rpy.sourceforge.net/rpy2/doc-2.1/html/robjects.html#functions