Thanks to Deepayan Sarkar (lattice) and Paul Murrell (grid)
I have nearly finished porting the Hmisc library's xYplot
function to R. xYplot extends xyplot to allow for error bars,
bands, and a few other features. In S-Plus I extended the
Trellis function xyplot mainly by writing panel.xYplot.
In R, xyplot contains a lot of code, so I implemented xYplot
by calling xyplot from it. Things are working quite well but
I would appreciate advice on programming the most elegant
solution to passing unevaluated arguments.
Here's the situation. xYplot needs to fiddle with
arguments formula and data (which I default to
sys.frame(sys.parent()) which I believe will pass through
to xyplot OK). There are several arguments passed
through to xyplot which were the "..." arguments to xYplot.
I want to defer evaluation of these to inside xyplot where
it will evaluate the arguments with respect to the
"data" argument. A good example is the groups= variable:
xYplot(formula, data=d, groups=g)
where g might be in d or in the frame that invoked
xYplot. Using for example do.call("xyplot", list(...))
from within xYplot will result in "g not defined".
I can do something like
if(!missing(groups)) groups <- eval(substitute(groups),data)
inside xYplot but I feel there is a more elegant approach
where I would not even have to isolate groups as a separate
argument, that experienced R programmers already know. I
would appreciate some ideas.
Thanks -Frank
--
Frank E Harrell Jr Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
fharrell at virginia.edu writes:> Here's the situation. xYplot needs to fiddle with > arguments formula and data (which I default to > sys.frame(sys.parent()) which I believe will pass through > to xyplot OK). There are several arguments passed > through to xyplot which were the "..." arguments to xYplot. > I want to defer evaluation of these to inside xyplot where > it will evaluate the arguments with respect to the > "data" argument. A good example is the groups= variable: > > xYplot(formula, data=d, groups=g) > > where g might be in d or in the frame that invoked > xYplot. Using for example do.call("xyplot", list(...)) > from within xYplot will result in "g not defined". > I can do something like > > if(!missing(groups)) groups <- eval(substitute(groups),data)I think eval(substitute(xyplot(...)), data, environment(formula)) will get you there if xYplot is function(formula,data,...). environment(formula) is somewhat preferable to parent.frame() in general, although they're usually the same thing. The tricky bit is when you want to mix external arguments with something computed inside xYplot. We just had this aired on R-core in a similar context, and I *think* you get by with substituting in local variables (notice that R's substitute() is not quite identical to S's). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._