Re: [R] dot in formula

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri 03 Jun 2005 - 17:52:29 EST

Adrian Baddeley <adrian@maths.uwa.edu.au> writes:

> gReetings,
>
> I want to manipulate a formula object, containing the name "."
> so that "." is replaced by a desired (arbitrary) expression.

> What is a safe way to do this?

I'm not vouching for the safety, but something along the lines of

mycall <- quote(a+b) # NOT mode "expression" substitute(~., list(.=mycall))

or (this stuff is such a pain)

eval(substitute(substitute(formula, list(.=mycall)), list=myformula))

Notice, BTW, that formulas can have "." on both sides, so you may want to do it only to either the LHS or RHS as appropriate. Also note that the substitute operations loses the the class and environment of the original, so you may need to put that back in place with as.formula and environment<-

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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Jun 03 18:08:06 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:22 EST