In my attempts to avoid creating intermediate objects to generate R DataFrames (to reduce the memory footprint), I've been trying many approaches. Unfortunately some of them fail using rpy2.
As an example: matrix = robjects.baseenv.get("matrix") # create an empty matrix random = matrix(nrow=5, ncol=5, dimnames=robjects.ListVector({1: robjects.StrVector(["a", "b", "c", "d", "e"]), 2: robjects.StrVector(["first","second", "third", "fourth", "fifth")})) #Try to set first row, first column to something else random.rx[1,1] = 5 /usr/lib64/python2.7/site-packages/rpy2/robjects/vectors.pyc in __setitem__(self, item, value) 94 res = fun(*args) 95 #FIXME: check refcount and copying ---> 96 self._parent.__sexp__ = res.__sexp__ 97 98 ValueError: Mismatch in SEXP type (as returned by typeof) Likewise, if I convert this to a data.frame, setting with rx2 accessors fails with an R error as_data_frame = robjects.baseenv.get("as.data.frame") random = as_data_frame(random) random.rx2["first"] = [1,2,3,4,5] /usr/lib64/python2.7/site-packages/rpy2/robjects/vectors.pyc in __setitem__(self, item, value) 92 conversion.py2ro(item), 93 conversion.py2ro(value)] ---> 94 res = fun(*args) 95 #FIXME: check refcount and copying 96 self._parent.__sexp__ = res.__sexp__ RRuntimeError: Error in [[<-.data.frame`(list(src = c(NA, NA, NA, NA, NA, NA, NA, NA, : argument "values" is missing, with no default It looks like a limitation on rpy2's part, as both approaches work in pure R. -- Luca Beltrame, Ph.D. - Translational Genomics Unit Oncology Department, Mario Negri Institute
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ For Developers, A Lot Can Happen In A Second. Boundary is the first to Know...and Tell You. Monitor Your Applications in Ultra-Fine Resolution. Try it FREE! http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list