[R] substitute question

Gabor Grothendieck ggrothendieck at myway.com
Fri Mar 19 00:06:36 CET 2004


> Date:   18 Mar 2004 23:52:47 +0100 
> From:   Peter Dalgaard <p.dalgaard at biostat.ku.dk>
> To:   <ggrothendieck at myway.com> 
> Cc:   <p.dalgaard at biostat.ku.dk>, <tlumley at u.washington.edu>, <tplate at blackmesacapital.com>, <R-help at stat.math.ethz.ch> 
> Subject:   Re: [R] substitute question 
> 
>  
> "Gabor Grothendieck" <ggrothendieck at myway.com> writes:
> 
> > From: Peter Dalgaard <p.dalgaard at biostat.ku.dk>
> > > (The real pain in these examples is that substitute autoquotes its
> > > expr argument. Therefore, when you want to modify an expression that
> > > is already stored in a variable, you need an extra outer layer of
> > > eval(substitute(...)) to poke the content of the variable into the
> > > inner substitute. An "esub" function with standard evaluation
> > > semantics would make this much easier.)
> > 
> > That is one of the frustrations of using substitute. 
> > 
> > The other is that even if you do perform two levels of substitute,
> > as I have been trying, you still can't count on it working for
> > an arbitrary unevaluated expression, as my examples show. 
> 
> Er, I don't think so. All I have seen is a couple of cases where you
> tried to pass something that was not a language object (e.g. a
> function as opposed to an expression or call generating a function.)
> 
> 

The parse/deparse one definitely is an expression:

> z <- parse(text=deparse(f))
> class(z);mode(z);typeof(z)
[1] "expression"
[1] "expression"
[1] "expression"

In the other one, it is not an expression in the inner substitute
but should be by the time it gets to the outer one since I
explicitly added expression(...).  It is expanded which shows
it did do that part right.




More information about the R-help mailing list