Hi all,
I've figured out part of the problem and the full solution and wanted to post
the solution. The problem is that the .rcall(kv, globalenv_ri) method uses the
keys of the dictionary kv as the keyword arguments. It was failing because the
keyword arguments were in unicode and not string. Apparently this is a bug in
some versions of Python 2.6. It seemed to work fine for me except with the
Django webservice. I still do not know why it works on all my interpreters
except when running python manage.py runserver.
But the quick fix is to manually cast the keywords in kv to string. I made a
minor modification to vectors.py where I convert k into a string as str(k)
inside the list iteration below. This fixed the problem.
Thanks,
Henry
kv = [(str(k), conversion.py2ri(v)) for k,v in tlist.iteritems()]
kv = tuple(kv)
df = baseenv_ri.get("data.frame").rcall(kv, globalenv_ri)
On Jan 5, 2011, at 1:14 PM, Henry Ward wrote:
> Hello all,
>
> I'm new to the list and I'm hoping I might be able to find help for a very
> mysterious failure within the RPY2 code base. I am converting a python
> dictionary of arrays into an R DataFrame. The conversion works fine when I
> run the code from iPython command line. However, when I run exactly the same
> code within a Django session it fails without an error message. It just
> exits the __init__ method.
>
> I have used Eclipse Debug to find the exact line of failure and it is the
> following line
>
> df = baseenv_ri.get("data.frame").rcall(kv, globalenv_ri)
>
> in __init__() of rpy2.robjects.vectors.DataFrame.
>
> I've copied the __init__ at the bottom of the email from
> rpy2.objects.vectors.DataFrame for reference.
>
> I have been able to user other classes/methods within the
> rpy2.robjects.vector in both Django and the command line to convert vectors,
> arrays, lists, etc.... It is only DataFrame that I've discovered an issue
> and its only when called from a Django session. Once again, command line
> works fine.
>
> I have confirmed multiple times that the Django interpreter is the same as my
> command line interpreter. I am using python 2.6.6 32-bit and R version 2.12
> and rpy2-2.1.9_20101221-py2.6-macosx-10.5-i386.egg (though I am on snow
> leopard).
>
> It is a very strange issue because I can only recreate the issue in a Django
> runserver session (it even works fine in a python manage.py -shell session).
> And it does not provide any error. It simply fails at this line and exits
> the __init__.
>
> Does anybody have any insight into what might cause this? Its such a
> peculiar issue I don't even know where to start debugging the rpy2 code. Any
> thoughts? Thanks in advance.
>
> Henry
>
>
> def __init__(self, tlist):
> """ Create a new data frame.
>
> :param tlist: rpy2.rlike.container.TaggedList or
> rpy2.rinterface.SexpVector (and of class 'data.frame' for R)
> """
> if isinstance(tlist, rlc.TaggedList):
> df = baseenv_ri.get("data.frame").rcall(tlist.items(),
> globalenv_ri)
> super(DataFrame, self).__init__(df)
> elif isinstance(tlist, rinterface.SexpVector):
> if tlist.typeof != rinterface.VECSXP:
> raise ValueError("tlist should of typeof VECSXP")
> if not globalenv_ri.get('inherits')(tlist,
> self._dataframe_name)[0]:
> raise ValueError('tlist should of R class "data.frame"')
> super(DataFrame, self).__init__(tlist)
> elif isinstance(tlist, dict):
> kv = [(k, conversion.py2ri(v)) for k,v in tlist.iteritems()]
> kv = tuple(kv)
> df = baseenv_ri.get("data.frame").rcall(kv, globalenv_ri)
> super(DataFrame, self).__init__(df)
> else:
> raise ValueError("tlist can be either "+
> "an instance of
> rpy2.rlike.container.TaggedList," +
> " or an instance of rpy2.rinterface.SexpVector" +
> " of type VECSXP, or a Python dict.")
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl_______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list