Exemple #1
0
 def __getitem__(self, i: int) -> typing.Union[float, 'FloatSexpVector']:
     cdata = self.__sexp__._cdata
     if isinstance(i, int):
         i_c = _rinterface._python_index_to_c(cdata, i)
         res = openrlib.REAL_ELT(cdata, i_c)
     elif isinstance(i, slice):
         res = type(self).from_iterable([
             openrlib.REAL_ELT(cdata, i_c)
             for i_c in range(*i.indices(len(self)))
         ])
     else:
         raise TypeError('Indices must be integers or slices, not %s' %
                         type(i))
     return res
Exemple #2
0
def test_get_real_elt_fallback():
    rpy2.rinterface.initr()
    v = rpy2.rinterface.FloatSexpVector([1.1, 2.2, 3.3])
    assert (openrlib.REAL_ELT(v.__sexp__._cdata, 1) \
            == \
            openrlib._get_real_elt_fallback(v.__sexp__._cdata, 1))