I'm trying to use
rcall following the example in the docs:
import rpy2.rlike.container as rpc args = rpc.OrdDict() args['x'] = rinterface.IntSexpVector([1,2,3]) args[None] = rinterface.IntSexpVector([4,5]) args['y'] = rinterface.IntSexpVector([6, ]) rlist = rinterface.baseenv['list'] rl = rlist.rcall(args.items(), rinterface.globalenv)
My code looks as follows:
reshape2 = importr("reshape2") rcall_args = rpc.OrdDict() rcall_args[None] = r_data # a data frame rcall_args['measure.vars'] = ri.StrSexpVector(("start", "end")) gantt_frame = reshape2.melt(rcall_args.items(), ri.globalenv)
The first problem that I encountered is in the last line which uses the
items() function of
OrdDict. When running this, I get the following error:
NotImplementedError: Conversion 'py2ri' not defined for objects of type '<type 'listiterator'>'
Now I looked into
OrdDict and found that it defines the
items() function twice:
... def items(self): """ Return an ordered list of all key/value pairs """ res = [self.byindex(i) for i in range(len(self.__l))] return tuple(res) ... def items(self): """ OD.items() -> an iterator over the (key, value) items of D """ return iter(self.__l) ...
So the first one is of course overridden by the second one.
I think this is a bug, no? The function should be defined only once, right?
(Not sure how issue
#259 is connected to this as it also suggests to create a tuple.)
Then I changed the class a bit to get access to the first version of the function and I get the following error:
NotImplementedError: Conversion 'py2ri' not defined for objects of type '<type 'tuple'>'
So it seems that neither is supported in the conversion. So how would
rcall with an
OrdDict ever work?
I'm running python 2.7.10 and rpy2 version 2.8.4