On 2013-03-21 02:59, Luca Beltrame wrote:
This occurs with the latest 2.3. Example case:

robjects.IntVector([0,1,2]) + 1

This is what it returns

<IntVector - Python:0x7fadd7a7a320 / R:0xb385b18>
[       0,        1,        2,        1]

While I'd expect, like in R

c(0,1,2) + 1
[1] 1 2 3

Is this a bug, or do I have to do things differently?


The idea was that a vector would behave like a Python sequence. For example

>>> x = [1,2]
>>> x + [3, ]
[1,2,3]
Now where I met ambiguity bridging the two worlds (Python and R) is that there is no such thing as a scalar in R (they are vectors of length 1).
In Python this is an error.
>>> x+3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "int") to list

Since I am converting Python scalars into vectors whenever passing them to R I must have thought that this should be the same for when __add__ is used. Now I see that in the current robjects model, `robjects.IntVector([0,1,2]) + 1` should raise a type Error.

To use R-style operation, I solved this by adding a delegating attribute called `ro` (R operator).
For example here:
robjects.IntVector([0,1,2]).ro + 1
(documentation is here:
http://rpy.sourceforge.net/rpy2/doc-2.3/html/vector.html#operators
).

L.



------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar


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

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to