[R] substitute question

Tony Plate tplate at blackmesacapital.com
Fri Mar 19 00:41:31 CET 2004


Gabor, you might have less frustration if you work with Peter's esub() 
suggestion (use it instead of substitute()):

esub <- function(expr, subst.list) do.call("substitute", list(expr, 
subst.list))

When you say

"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."

something to bear in mind is the "natural order" of evaluation is reversed 
with nested substitute()'s (because the inner substitute() is quoted by the 
outer substitute())  (but I haven't carefully reasoned through this being 
an explanation for your particular frustration here.)

hope this might help,

Tony Plate




At Thursday 04:06 PM 3/18/2004, Gabor Grothendieck wrote:

> > 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.
>
>
>
>
>_______________________________________________
>No banners. No pop-ups. No kidding.
>Introducing My Way - http://www.myway.com




More information about the R-help mailing list