def sexp(_, s): # noqa n = len(s) x = lib.Rf_allocVector(lib.VECSXP, n) with protected(x): for i in range(n): lib.SET_VECTOR_ELT(x, i, sexp(s[i])) return x
def sexp(_, s): # noqa n = len(s) x = lib.Rf_allocVector(lib.REALSXP, n) with protected(x): p = lib.REAL(x) for i in range(n): p[i] = s[i] return x
def sexp(_, s): # noqa n = len(s) x = lib.Rf_allocVector(lib.RAWSXP, n) with protected(x): p = lib.RAW(x) for i in range(n): p[i] = ord(s[i]) return x
def sexp(_, s): # noqa n = len(s) x = lib.Rf_allocVector(lib.CPLXSXP, n) with protected(x): p = lib.COMPLEX(x) for i in range(n): p[i].r = s[i].real p[i].i = s[i].imag return x
def sexp(_, s): # noqa n = len(s) x = lib.Rf_allocVector(lib.STRSXP, n) with protected(x): for i in range(n): isascii = all(ord(c) < 128 for c in s[i]) b = s[i].encode('utf-8') lib.SET_STRING_ELT( x, i, lib.Rf_mkCharLenCE(b, len(b), 0 if isascii else 1)) return x
def rlang_p(f, *args, **kwargs): ensure_initialized() argslist = list(args) + list(kwargs.items()) with protected(*argslist): nargs = len(args) + len(kwargs) t = lib.Rf_allocVector(lib.LANGSXP, nargs + 1) with protected(t): s = t lib.SETCAR(s, as_call(f)) for a in args: s = lib.CDR(s) lib.SETCAR(s, unbox(a)) for k, v in kwargs.items(): s = lib.CDR(s) lib.SETCAR(s, unbox(v)) lib.SET_TAG(s, lib.Rf_install(utf8tosystem(k))) ret = t return ret