rpy2 importr failing with xts and quantmod

后端 未结 1 421
时光说笑
时光说笑 2021-01-14 06:30

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 im         


        
相关标签:
1条回答
  • 2021-01-14 07:21

    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.

    0 讨论(0)
提交回复
热议问题