def __setitem__(self, i: int, value) -> None: cdata = self.__sexp__._cdata if isinstance(i, int): i_c = _rinterface._python_index_to_c(cdata, i) openrlib.SET_INTEGER_ELT(cdata, i_c, int(value)) elif isinstance(i, slice): for i_c, v in zip(range(*i.indices(len(self))), value): openrlib.SET_INTEGER_ELT(cdata, i_c, int(v)) else: raise TypeError('Indices must be integers or slices, not %s' % type(i))
def _int_to_sexp(val: int): rlib = openrlib.rlib # TODO: test value is not too large for R's ints s = rlib.Rf_protect(rlib.Rf_allocVector(rlib.INTSXP, 1)) openrlib.SET_INTEGER_ELT(s, 0, val) rlib.Rf_unprotect(1) return s
def _int_to_sexp(val: int): rlib = openrlib.rlib # TODO: _rinterface._MAX_INT is determined empirically. if val > _rinterface._MAX_INT: raise ValueError( f'The Python integer {val} is larger than {_rinterface._MAX_INT} (' 'R\'s largest possible integer).' ) s = rlib.Rf_protect(rlib.Rf_allocVector(rlib.INTSXP, 1)) openrlib.SET_INTEGER_ELT(s, 0, val) rlib.Rf_unprotect(1) return s