[Rd] Modifying parsed code

2006-07-07 Thread hadley wickham
I would like to take this: .img(plot(1:10), filename=a) and produce plot(1:10) ie. whenever .img is used, I want to take the first argument and throw away everything else. (I am trying to produce a Sweave like environment in which I can apply certain functions, but not have them displayed in

Re: [Rd] Modifying parsed code

2006-07-07 Thread Gabor Grothendieck
Assuming the desired output is a character string try: f - function(x) deparse(substitute(x)) f(3+y) [1] 3 + y On 7/7/06, hadley wickham [EMAIL PROTECTED] wrote: I would like to take this: .img(plot(1:10), filename=a) and produce plot(1:10) ie. whenever .img is used, I want to take

Re: [Rd] Modifying parsed code

2006-07-07 Thread Duncan Murdoch
On 7/7/2006 8:08 AM, hadley wickham wrote: I would like to take this: .img(plot(1:10), filename=a) and produce plot(1:10) ie. whenever .img is used, I want to take the first argument and throw away everything else. (I am trying to produce a Sweave like environment in which I can

Re: [Rd] Modifying parsed code

2006-07-07 Thread hadley wickham
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

Re: [Rd] Modifying parsed code

2006-07-07 Thread Prof Brian Ripley
On Fri, 7 Jul 2006, hadley wickham wrote: I would like to take this: .img(plot(1:10), filename=a) I presume from your title that you want to take foo - parse(text='.img(plot(1:10), filename=a)') ? That's an expression. In which case foo[[1]][[2]] plot(1:10) (first expression which a