From ripley at stats.ox.ac.uk  Fri Jul  7 15:03:01 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 7 Jul 2006 14:03:01 +0100 (BST)
Subject: [Rd] Modifying parsed code
In-Reply-To: <f8e6ff050607070508h7fe3807fu739763f80a472be0@mail.gmail.com>
References: <f8e6ff050607070508h7fe3807fu739763f80a472be0@mail.gmail.com>
Message-ID: <Pine.LNX.4.64.0607071400060.22368@gannet.stats.ox.ac.uk>

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 call, and calls are symbol, arg1, arg2 ...).

>
> 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 the output)
>
> I think I should be able to do it using substitute, but I don't know
> how to operate on language objects.  Any hints would be appreciated.
>
> Thanks,
>
> Hadley
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Modifying parsed code
Prof Brian Ripley