1

I am using rpy2 to call R packages in Python and I am facing technical problems. Some functions in R packages have a dot "." in their names, so it is hard for Python to identify these functions. For example, there is a function called "Granger.conditional()" in the R package called "grangers". When I use rpy2 to call the function like this:

grangers = rpackages.importr('grangers')
res = grangers.Granger.conditional(trnsetmdl_i.iloc[:, i], trnsetmdl_i.iloc[:, j], trnsetmdl_i.iloc[:, k])

I am getting the following error message:

Traceback (most recent call last):
  File "D:/CMAPSSRUL/TimeSeriesModelling/GrangerCausality/ConditionalGC.py", line 53, in <module>
  res = grangers.Granger.conditional(trnsetmdl_i.iloc[:, i], trnsetmdl_i.iloc[:, j], trnsetmdl_i.iloc[:, k])
  AttributeError: module 'grangers' has no attribute 'Granger'

Anyone has solutions to this problem?

mac13k
  • 2,423
  • 23
  • 34
Eric94
  • 29
  • 2
  • Did you check https://stackoverflow.com/questions/6032060/accessing-functions-with-a-dot-in-their-name-eg-as-vector-using-rpy2 ? – agila Mar 06 '20 at 18:18

1 Answers1

1

The answer to the question is in the documentation: https://rpy2.github.io/doc/v3.2.x/html/robjects_rpackages.html#importing-r-packages

Also, I see from your error message that you are using Windows. Note that rpy2 is not supported, and pre-built binaries you may have found are almost certainly several releases behind the current one.

lgautier
  • 11,363
  • 29
  • 42
  • Many thanks for this! I actually use an old version of the rpy2 based on Python 3.7, and it is going well so far. – Eric94 Mar 07 '20 at 22:21