[R] dot in formula

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Jun 3 09:52:29 CEST 2005


Adrian Baddeley <adrian at 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 at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list