[Rd] Questions about calls and formulas
murdoch at stats.uwo.ca
Tue Aug 23 04:21:50 CEST 2005
Erich Neuwirth wrote:
>>Try do.call like this:
>>ff <- x ~ g*h
>>do.call("substitute", list(ff, list(x = as.name("weight"))))
> It is even more complicated.
> All I know is that ff is a formula with an expression on the left hand
> side. This expression needs to be replaced by "weights".
> According to the documentation, substitute only handles
> replacement of variables by something else,
> and that is not enough in my case.
That may make it simpler. For example:
> ff <- x ~ g*h
> ff[] <- as.name("weights")
weights ~ g * h
If you know that ff is a formula with an expression on the left that you
want to replace with "weights", then ff[] <- as.name("weights")
will work. (ff[] is the tilde, ff[] is the RHS. You'll probably
want some sanity checks in your code to confirm this.)
More information about the R-devel