D. R. Evans wrote: > I have the following piece of R code: > > ---- > > # next line loads a variable called "dat" > load('/tmp/dat.R') > > # make a copy > d <- dat > > # extract the dat$web fields for the future > d <- subset(d, web == 'future') > > ---- > > In rpy, I figured out that the equivalent starts out with: > > r.load('/tmp/dat.r') # creates a variable called r.dat > d = r.dat # make a copy > > but I don't know what the next line should look like. > > I tried the obvious: > d = r.subset(d, web == 'future') > > but that sure didn't go well. Neither did anything else I tried :-( > Everything seems to cause python to complain that it doesn't know anything > about "web".
Python should know about d["web"] but I don't think that will help. > so could someone please tell me what that line should look like (and why)? One option would be to start by having the d variable in python but as an R object by turning off rpy's default object conversion. Right now, you end up with a poor approximation of the R object, probably as a python dictionary (my guess - I haven't checked this). If you are happy having this as a dictionary, then this would probably do what you want: del d['future'] Am I right in assuming the following works fine in pure R?: d <- load('/tmp/dat.R') d <- subset(d, web == 'future') If so, I would suggest something like this - which avoids converting the "d" object from R by instead keeping "d" within R: from rpy import r r("d <- load('/tmp/dat.R')") r("d <- subset(d, web == 'future')") print r("d") And if you still want to assign it to a variable within python, perhaps turn off the default conversion, then: d = r("d") Take this with a pinch of salt - I haven't actually tested these snippets of code, I'm working from memory here. Peter ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list