Re: [Rd] Questions about calls and formulas

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 22 Aug 2005 - 22:55:38 GMT

On 8/22/05, Erich Neuwirth <erich.neuwirth@univie.ac.at> wrote:
> >
> >>(foo <- eval(substitute(x ~ g * h, list(x = as.name("weights")))))
> >
> > weights ~ g * h
> >
> >>class(foo)
> >
> > [1] "formula"
> >
> >
>
> ff<-formula("x~g*h")
> (foo<-eval(substitute(ff,list(x=as.name("weights")))))
>
> gives
>
> x ~ g * h
>
> what needs to be done to ff for the substitution to work?
>
> I found a way of doing it using string substitution
> and applying formula (instead of as.call) to the string,
> but I would like to be able to do it using substitution.
>
> This is what I currently do:
>
> myexpr<-paste("weights ~",strsplit(deparse(m$formula),"~")[[1]][2])
> m$formula<-formula(myexpr)

Try do.call like this:

ff <- x ~ g*h
do.call("substitute", list(ff, list(x = as.name("weight"))))



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Aug 23 09:12:04 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:18 GMT