Re: [Rd] Modifying parsed code

From: hadley wickham <h.wickham_at_gmail.com>
Date: Fri 07 Jul 2006 - 12:59:16 GMT

> 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



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Jul 07 23:02:01 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 07 Jul 2006 - 14:24:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.