Element-wise comparison of vector and scalar fails in rpy2 with Python 3
<p>It looks like rpy2 doesn't behave exactly the same in Python3 and Python2. In particular, in Python 2.7.x, I am able to compare a <a href="http://rpy2.readthedocs.io/en/version_2.8.x/vector.html" rel="nofollow">Vector</a> with a scalar, whereas in Python 3.5.x, if I try to do that, the following error is raised: </p>

<pre><code>TypeError: unorderable types: IntVector() &gt; int()
</code></pre>

<p>Here is a snippet of my code:</p>

<pre><code>&gt;&gt;&gt; from rpy2 import robjects
&gt;&gt;&gt; x = robjects.IntVector([5, -1])
&gt;&gt;&gt; x &gt; 0
</code></pre>

<p>And here is an extract of my <code>pip freeze</code> (same in both environments):</p>

<pre><code>rpy2==2.8.2
numpy==1.11.1
</code></pre>

<p>I would like to understand if it's a bug in rpy2 or simply a different behaviour of some library that rpy2 relies on (numpy for example).</p>

<p>If a bug, I would think that it was with Python 2.</p>

<p>An R vector is a sequence and the default Python behavior does not make such comparisons possible. For example:</p>

<pre><code>&gt;&gt;&gt; [1,2,3] &lt; 2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-5-f7a2f4fe21e0&gt; in &lt;module&gt;()
----&gt; 1 [1,2,3] &lt; 2

TypeError: unorderable types: list() &lt; int()
</code></pre>

<p>On the other hand, R's vectorized counterpart can be called throught the delegator <code>.ro</code> (as in "R Operator"). See <a href="https://rpy2.readthedocs.io/en/version_2.8.x/vector.html#operators" rel="nofollow">https://rpy2.readthedocs.io/en/version_2.8.x/vector.html#operators</a></p>

<pre><code>&gt;&gt;&gt; v = IntVector([1,2,3])
&gt;&gt;&gt; v.ro &lt; 2 
R object with classes: ('logical',) mapped to:
&lt;BoolVector - Python:0x7fc7789a5a08 / R:0x22d25f8&gt;
[       1,        0,        0]
</code></pre>

python python-3.x numpy rpy2