On Sun, 2008-11-16 at 22:25 -0800, Nathaniel Smith wrote:
> rpy2 is awesome.
>
> But I was disconcerted to discover passing a numpy array to an R
> function just makes things blow up ("Nothing can be done for that
> type...") --
Complete error messages are:
"Nothing can be done for this array type at the moment."
or
"Nothing can be done for the type %s at the moment." %(type(o))
The attentive reader will note the time statement "at the moment",
denoting the likely intent of restricting the behaviour to a limited
stretch of time.
> who uses rpy without numpy?
The R-to-numpy bridge is (officially) working.
(The other way around is not sorted out - I'd like to have that at the
lower level -rpy2.rinterface- as well).
It is currently possible to create vector/array structures in R and use
them with numpy.
Consider the following example (taken from the rpy2 documentation):
import rpy2.rinterface as ri
import numpy
rx = ri.FloatSexpVector([1.1, 2.2, 3.3])
# using array, a copy is made
nx = numpy.array(rx)
# using asarray, no copy is made:
nx_nc = numpy.asarray(rx)
>>> rx[2]
3.299999
>>> nx_nc[2] = 42
>>> rx[2]
42.0
> :-) So I fixed it.
>
> Strategy:
> * most numpy arrays are mapped to R arrays (shape is preserved)
> * a numpy object array is treated like a python list, and mapped to an R list
> * a numpy record array is mapped to an R data frame
> The patch does not introduce any dependency on numpy, is against
> current trunk,
That's fine, trunk is currently 2.1-dev.
2.0.x is already in a branch.
> and includes complete tests.
Something offered with unit tests will indeed be hard to refuse. ;-)
I'd like to review the patch before inclusion (hopefully next week-end).
In the meanwhile, you should already be able to distribute the code as a
an alternative py2ro() function.
(see
http://rpy.sourceforge.net/rpy2/doc/html/robjects.html#mapping-rpy2-objects-to-arbitrary-python-objects
)
Thanks for the contribution,
L.
> Yes/no?
>
> -- Nathaniel
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________ rpy-list mailing list
> rpy-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rpy-list
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list