def testExternalPython(self): def f(x): return 3 rpy_fun = rinterface.SexpExtPtr(f, tag=rinterface.python_type_tag) _python = rinterface.StrSexpVector(('.Python', )) res = rinterface.baseenv['.External'](_python, rpy_fun, 1) self.assertEqual(3, res[0]) self.assertEqual(1, len(res))
def testNewProtected(self): pyobject = "ahaha" sexp_new = rinterface.SexpExtPtr( pyobject, protected=rinterface.StrSexpVector("c")) self.assertEqual(rinterface.EXTPTRSXP, sexp_new.typeof) self.assertEqual('c', sexp_new.__protected__[0])
def testNewTag(self): pyobject = "ahaha" sexp_new = rinterface.SexpExtPtr(pyobject, tag=rinterface.StrSexpVector("b")) self.assertEqual(rinterface.EXTPTRSXP, sexp_new.typeof) self.assertEqual('b', sexp_new.__tag__[0])
def testNewDefault(self): pyobject = "ahaha" sexp_new = rinterface.SexpExtPtr(pyobject) # R External pointer are never copied self.assertEqual(rinterface.EXTPTRSXP, sexp_new.typeof)
import numpy as np import pandas as pd import pyarrow as pa df = pd.DataFrame({"a": [1, 2, 3]}) table = pa.Table.from_pandas(df) import rpy2.robjects as robjects import rpy2.rinterface as rinterface rinterface.initr() func = robjects.r(""" f = function(inputs) { require(RcppPyArrow) require(arrow) df = RcppReceiveArrowTableFromPython(inputs) print (dim(df)) print (head(df)) } """) param = rinterface.SexpExtPtr(table) response = func(param)