我是 rpy2 新手,在使用 importr 导入 R 包“xts”和“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 时我没有遇到这个问题。 “统计”、“图形”、“动物园”、“ggplot2”
版本:
- Python 版本 2.7.3
- R 版本 2.15.2
- rpy2 版本“2.3.0beta1”
任何帮助将不胜感激
最佳答案
Rpy2 的 importr()
正在尝试转换任何“.”将 R 对象名称中的名称更改为“_”以便与 Python 一起使用。
但是,每当有两个 R 对象名称带有“.”时或“_”(这两个字符对于 R 中的名称均有效) rpy2 报告错误。这里,R 包“xts”定义了两个对象 .subset_xts
和 .subset.xts
。解决方法是手动指定如何转换名称:
from rpy2.robjects.packages import import
xts = importr("xts", robject_translations = {".subset.xts": "_subset_xts2",
"to.period": "to_period2"})
rpy2 文档中提供了有关 importing R packages 的更多信息。 .
关于rpy2 importr 因 xts 和 quantmod 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13649562/