问题描述
我是rpy2的新手,在使用importr导入R包'xts'和'quantmod'时遇到问题
I'm new to rpy2 and am having trouble using importr to import the R packages 'xts' and 'quantmod'
代码为:
from rpy2.robjects.packages import importr
xts = importr('xts')
quantmod = importr('quantmod')
错误是:
LibraryError: Conflict when converting R symbol in the package "xts" to a Python symbol (.subset.xts -> _subset_xts while there is already _subset_xts)
LibraryError: Conflict when converting R symbol in the package "quantmod" to a Python symbol (skeleton.TA -> skeleton_TA while there is already skeleton_TA)
对于许多其他软件包,使用importr我没有遇到这个问题'stats','graphics','zoo','ggplot2'
I don't get this problem using importr for many other packages, e.g. 'stats', 'graphics', 'zoo', 'ggplot2'
版本:
- python版本2.7.3
- R版本2.15.2
- rpy2版本'2.3.0beta1'
任何帮助将不胜感激
推荐答案
Rpy2的 importr()
试图转换任何。
Rpy2's importr()
is trying to convert any "." in R object names to "_" for usage with Python.
但是,只要有两个带有。的R对象名,就可以使用。或 _(两个字符均对R中的名称有效)rpy2报告错误。这里的R包 xts定义了两个对象 .subset_xts
和 .subset.xts
。解决方法是手动指定如何转换名称:
However, whenever there are two R object names with either "." or "_" (both characters are valid for names in R) rpy2 is reporting an error. Here the R package "xts" is defining the two objects .subset_xts
and .subset.xts
. The workaround is specify manually how to convert names:
from rpy2.robjects.packages import import
xts = importr("xts", robject_translations = {".subset.xts": "_subset_xts2",
"to.period": "to_period2"})
rpy2文档中提供了有关。
More is available in the rpy2 documentation about importing R packages.
这篇关于rpy2导入器失败,xts和quantmod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!