On Tue, 2009-02-03 at 13:30 -0800, Nathaniel Smith wrote: > why does EnvironmentSexp_ass_subscript (== > rpy2.rinterface.SexpEnvironment.__setitem__) copy the value it is > storing? > > PROTECT(sexp_copy = Rf_duplicate(sexp)); > Rf_defineVar(sym, sexp_copy, rho_R);
That's from the early development days, when I was getting very frequent segfaults. That was to be on the safe side since R itself is often doing a lot of copies; a second look at that (and try to minimize the number of copies) is on the ever growing to-do list... > I noticed this because I was trying to get dim<- to work on an > SexpVector -- r["dim<-"](mysexp, newdim) doesn't work (more about that > in a follow-up note), and the workaround would be something like > globalEnv["mysexp"] = mysexp > globalEnv["newdim"] = newdim > r("dim(mysexp) <- newdim") > But that is thwarted by the above call to Rf_duplicate. I guess I > could do the above and then > mysexp = globalEnv["mysexp"] > but that seems silly. I am a little confused regarding whether you would like to do things at the robjects or the rinterface level. Either way, things seem to be working on my end. # rinterface import rpy2.rinterface as ri ri.initr() x = ri.FloatSexpVector([1,2,3,4]) x = ri.globalEnv.get("dim<-")(x, ri.IntSexpVector([2, 2])) ri.globalEnv.get("print")(x) # with robjects import rpy2.robjects as ro x = ro.FloatVector([1,2,3,4]) x = ro.r["dim<-"](x, ro.IntVector([2, 2])) L. > -- Nathaniel > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > rpy-list mailing list > rpy-list@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rpy-list ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list