From ggrothendieck at gmail.com  Tue Aug 23 00:55:38 2005
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Mon, 22 Aug 2005 18:55:38 -0400
Subject: [Rd] Questions about calls and formulas
In-Reply-To: <430A556E.4080203@univie.ac.at>
References: <430A4629.8010506@univie.ac.at>
	<40e66e0b05082214525e2140e8@mail.gmail.com>
	<430A556E.4080203@univie.ac.at>
Message-ID: <971536df050822155550243049@mail.gmail.com>

On 8/22/05, Erich Neuwirth <erich.neuwirth at 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"))))



[Rd] Questions about calls and formulas
Gabor Grothendieck