[Rd] Modifying parsed code

hadley wickham h.wickham at gmail.com
Fri Jul 7 14:59:16 CEST 2006


> 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



More information about the R-devel mailing list