Dear R-help, I find the example() function is extremely useful in many ways. However, there's a minor inconvenience: for long examples, it leaves lots of objects in the workspace. While it's sometimes useful to have the objects around for further exploration, other times they just add to the clutter. Does anyone have a good way of cleaning up afterward? If not, would R core consider adding such a feature? Cheers, Andy ------------------------------------------------------------------------------
On Mon, 16 Dec 2002, Liaw, Andy wrote:> I find the example() function is extremely useful in many ways. However, > there's a minor inconvenience: for long examples, it leaves lots of objects > in the workspace. While it's sometimes useful to have the objects around > for further exploration, other times they just add to the clutter. Does > anyone have a good way of cleaning up afterward? If not, would R core > consider adding such a feature?It's half there. Example calls source, and source has a local argument that by default uses the workspace for objects. We just need to call source(local=TRUE) in example(), and then the objects will get created in the frame of the example call. This BTW is to avoid creating the objects, not cleaning up. It is not possible (AFAIK) to find out what objects have been created, nor to know if they clobber existing objects of the same name. -- 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595
The example() and demo() functions are very useful and they do clutter up workspaces. For that reason, I run them (usually, I remember to do is) in a demo workspace. That way, I don't care about the objects or saving them etc. This makes cleaning up unnecessary. Anne ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Anne E. York National Marine Mammal Laboratory Seattle WA 98115-0070 USA e-mail: york at ofis450a.akctr.noaa.gov Voice: +1 206-526-4039 Fax: +1 206-526-6615 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ++++++++++++++++++++++++++++++++++++++++++ Date: Mon, 16 Dec 2002 22:33:27 -0500 From: "Liaw, Andy" <andy_liaw at merck.com> To: "'r-help at stat.math.ethz.ch'" <r-help at stat.math.ethz.ch> Subject: [R] cleaning up after example() Dear R-help, I find the example() function is extremely useful in many ways. However, there's a minor inconvenience: for long examples, it leaves lots of objects in the workspace. While it's sometimes useful to have the objects around for further exploration, other times they just add to the clutter. Does anyone have a good way of cleaning up afterward? If not, would R core consider adding such a feature? Cheers, Andy ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Anne E. York National Marine Mammal Laboratory Seattle WA 98115-0070 USA e-mail: anne.york at noaa.gov Voice: +1 206-526-4039 Fax: +1 206-526-6615 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Dear R-help, > > I find the example() function is extremely useful in many ways. However, > there's a minor inconvenience: for long examples, it leaves lots of objects > in the workspace. While it's sometimes useful to have the objects around > for further exploration, other times they just add to the clutter. Does > anyone have a good way of cleaning up afterward? If not, would R core > consider adding such a feature? >Andy, One quick fix would be to take a snapshot of your current workspace, then delete anything new afterwards. Of course, this doesn't account for overwritten variables.> snapshot = ls() > example("smooth",pack="eda",lib.loc=.Library)...> remove(list = ls()[!ls()%in%snapshot]) # also removes `snapshot'Regards, Sundar -- Sundar Dorai-Raj PDF Solutions, Inc. Dallas TX