Search code examples
pythonrrpy2

rpy2 importr failing with 'TTR' package


I've used rpy2 to import R packages before but am having trouble using importr to import the R packages 'TTR' code is:

import rpy2.robjects as robjects
from rpy2.robjects import pandas2ri  # for dataframes
pandas2ri.activate()
from rpy2.robjects.packages import importr
ttr = importr('TTR')

I'm getting Error as:

rpy2.robjects.packages.LibraryError: The symbol .env in the package "TTR" is conflicting with a Python object attribute

I've seen similar question rpy2 importr failing with xts and quantmod but for package 'TTR', I don't know what parameter to give in importr parameter robject_translations = ''


Solution

  • What the error message is telling is that the symbol .env in the R package, when translated to a syntactically valid name in Python (here the translation will be _env), is conflicting with an attribute of the object ttr you are creating when calling importr. You can see that attribute for objects of class Package here: https://rpy2.github.io/doc/v2.9.x/html/_modules/rpy2/robjects/packages.html#Package

    How to use the parameter robject_translationsis documented: https://rpy2.github.io/doc/v2.9.x/html/robjects_rpackages.html#importing-r-packages