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.