1

I am trying to pull R libraries into python so I can use them for data processing. The library in question is BNLearn. Using rpy2, I am able to pull BNLearn into python. However whenever I try to input a list into BNlearn, I receive the following error.

from rpy2.robjects.packages import importr
from rpy2.robjects import ListVector, StrVector

BNLearn = importr("bnlearn")

SList = ['a','b','c','d','e']

res = StrVector(SList)

BNLearn.empty_graph(res)

Traceback (most recent call last):

  File "/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py", line 345, in __call__
    return method()

  File "/anaconda3/lib/python3.7/site-packages/rpy2/robjects/vectors.py", line 683, in _repr_html_
    elements.append(e._repr_html_())

  File "/anaconda3/lib/python3.7/site-packages/rpy2/robjects/vectors.py", line 683, in _repr_html_
    elements.append(e._repr_html_())

  File "/anaconda3/lib/python3.7/site-packages/rpy2/robjects/vectors.py", line 690, in _repr_html_
    names.extend(self.names)

> TypeError: 'rpy2.rinterface.RNULLType' object is not iterable

I tried googling the error but not many posts talk about it. It claims the object is not iterable but if I use a basic python string, I receive the following

BNLearn.empty_graph(SList)

RRuntimeError: Error in check.nodes(nodes) : nodes must be a vector of character strings, the labels of the nodes.

StrVector was used to solve this error in the code above.

sophros
  • 14,672
  • 11
  • 46
  • 75
Hojo.Timberwolf
  • 985
  • 1
  • 11
  • 32
  • 1
    The traceback that is normally shown by Python when the `TypeError` occurs would be helpful. – lgautier Jul 08 '19 at 06:52
  • I added in the traceback for the error – Hojo.Timberwolf Jul 08 '19 at 07:24
  • At first sight this is an issue (bug) in rpy2's rendering of that object. `mygraph = BNLearn.empty_graph(res)` would likely work without error. Can you open an issue in the rpy2 issue tracker on bitbucket ? Thanks. – lgautier Jul 09 '19 at 12:09
  • stumbled on https://github.com/cs224/pybnl the other day. untested but perhaps useful. – user20650 Jul 19 '19 at 12:40

0 Answers0