On 21/04/10 22:30, Christian Marquardt wrote:
> Hi,
>
> once more my apologies if I'm missing the obvious...
>
> The rpy2 documentation at
> http://rpy.sourceforge.net/rpy2/doc-2.1/html/numpy.html#high-level-interface
> states that the import of the numpy2ri module "alone is sufficient to
> switch an automatic conversion of numpy objects into rpy2 objects."
> Based on that, I would have expected that something like
>
>     import numpy as np
>     import rpy2.robjects.numpy2ri
>     import rpy2.robjects as ro
>
>     x = np.arange(-10., 10., 0.1)
>
>     ro.globalenv["x"] = x
>
> works well. However, it generates the following error:
>
>    File "numpy_1.py", line 7, in<module>
>      ro.globalenv["x"] = x
>    File "/opt/apps/lib/python2.5/site-packages/rpy2/robjects/__init__.py",
> line 166, in __setitem__
>      robj = conversion.py2ro(value)
>    File "/opt/apps/lib/python2.5/site-packages/rpy2/robjects/__init__.py",
> line 143, in default_py2ro
>      res = default_py2ri(o)
>    File "/opt/apps/lib/python2.5/site-packages/rpy2/robjects/__init__.py",
> line 132, in default_py2ri
>      raise(ValueError("Nothing can be done for the type %s at the
> moment." %(type(o))))
> ValueError: Nothing can be done for the type<type 'numpy.ndarray'>  at
> the moment.
>
> It's of course straightforward to cast the numpy array explicitly with
>
>     ro.globalenv["x"] = ro.FloatVector(x)
>
> but why is this necessary? Wouldn' numpy2ri.py also need an
> inplementation of py2ro which makes sure that calls of
> conversion.py2ro are routed through the numpy aware version of py2ri?

Yes this is a problem, particularly since the following is already working:

 >>> ro.conversion.py2ri(x)
<Array - Python:0xa66b7cc / R:0xb016030>

Thanks for the report, this is in fact leading to a more serious bug.
Currently, robjects.Environment is in fact probably insensitive to any 
redefinition of conversion.py2ri.

I filed a bug report
https://bitbucket.org/lgautier/rpy2/issue/41/environment__setitem__-and-conversionpy2ri
Hopefully this will be fixed for 2.1.2.


Laurent




> Many thanks,
>
>    Christian.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list


------------------------------------------------------------------------------
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to