From p.dalgaard at biostat.ku.dk  Sat Apr  2 02:39:09 2005
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Sat Apr  2 02:39:18 2005
Subject: [Rd] An exercise in the use of 'substitute'
In-Reply-To: <424DE383.8020101@stat.wisc.edu>
References: <424DE383.8020101@stat.wisc.edu>
Message-ID: <x23bua6mhe.fsf@turmalin.kubism.ku.dk>

Douglas Bates <bates@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@biostat.ku.dk)             FAX: (+45) 35327907


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