rpy2 importr failing with xts and quantmod

落花浮王杯 提交于 2019-12-01 06:09:41

问题


I'm new to rpy2 and am having trouble using importr to import the R packages 'xts' and 'quantmod'

Code is:

from rpy2.robjects.packages import importr
xts = importr('xts')
quantmod = importr('quantmod')

Errors are:

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)

I don't get this problem using importr for many other packages, e.g. 'stats', 'graphics', 'zoo', 'ggplot2'

Versions:

  • python version 2.7.3
  • R version 2.15.2
  • rpy2 version '2.3.0beta1'

Any help would be greatly appreciated


回答1:


Rpy2's importr() is trying to convert any "." in R object names to "_" for usage with Python.

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"})

More is available in the rpy2 documentation about importing R packages.



来源:https://stackoverflow.com/questions/13649562/rpy2-importr-failing-with-xts-and-quantmod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!