[Rd] An exercise in the use of 'substitute'

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Apr 2 02:39:09 CEST 2005


Douglas Bates <bates at stat.wisc.edu> writes:
[..snip..]
> However, I haven't been able to work out a clever way of using
> substitute to get the first part.  I would like to be able to call,
> e.g.
> 
> with(fm, xyplot(resid(.) ~ carb))
> 
> and get a plot of resid(fm) ~ Formaldehyde$carb
> 
> It is possible to do the first part by deparsing, substituting, and
> parsing but that's inelegant.  Can anyone suggest a more elegant
> method?

Here's part of one, I think:

> w <- function(x,y)eval(substitute(substitute(y,list(.=quote(x)))))
> w(fm, xyplot(resid(.) ~ carb))
xyplot(resid(fm) ~ carb)

(The double substitute is often needed in this type of problem. Things
would be easier if we had a version of substitute that didn't
automatically quote it's argument.)

-- 
   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



More information about the R-devel mailing list