From h.wickham at gmail.com  Fri Jul  7 14:59:16 2006
From: h.wickham at gmail.com (hadley wickham)
Date: Fri, 7 Jul 2006 13:59:16 +0100
Subject: [Rd] Modifying parsed code
In-Reply-To: <f8e6ff050607070508h7fe3807fu739763f80a472be0@mail.gmail.com>
References: <f8e6ff050607070508h7fe3807fu739763f80a472be0@mail.gmail.com>
Message-ID: <f8e6ff050607070559n5ddb20d1id26446f8e8a0769b@mail.gmail.com>

> I would like to take this:
>
> .img(plot(1:10), filename="a")
>
> and produce
>
> plot(1:10)
>

Peter Dalgaard provided me with this:

f <- function(e) {
 if (!is.recursive(e)) e
 else if (e[[1]] == quote(.img)) e[[2]]
 else as.call(lapply(e, f))
}

> f(quote({a<-1;.img(abc,123)}))
{
   a <- 1
   abc
}

which is exactly what I was looking for.  Thanks Peter!

Hadley



[Rd] Modifying parsed code
hadley wickham