[R] automatic cleaning of workspace

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Nov 28 01:28:09 CET 2006


On Mon, 2006-11-27 at 18:29 -0500, Leeds, Mark (IED) wrote:
> I'm having that problem where I am sometimes using an object that's from
> a previous workspace when I don't want to be doing that. I was thinking
> of putting rm(objects=ls()) in my first.R function But, the problem with
> doing this, is that it doesn't prompt you with "are you sure" and there
> could be very rare cases where I don't want to delete the workspace ? Is
> there a way to
> make the cleaning of the workspace automatic but still prompt you ? I
> guess I can always just try to remember to manually 
> do rm(objects=ls())when I start up in whatever workspace I am in but I
> don't think I can trust my memory. Thanks.

I assume you are saving your workspace when exiting R, and then when
restarting R in same directory it is auto loading the saved workspace?

If so, try not saving the workspace at the end of the session when
quitting, but explicitly save the objects you wish to save using save()
and load() it when restarting.

You might need to locate and delete the file .Rdata in the working
directory first, before you start R for example, to stop it being loaded
when you start R again. Alternatively, give it a new name with a .Rdata
extension, so you can load the workspace again if needed.

You might also want save.image if you are interested in saving
workspaces rather than individual objects.

This way you are in control of what is and is not saved/reloaded and you
won't have to rely on your memory.

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC & ENSIS, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/cv/
 London, UK. WC1E 6BT.         [w] http://www.ucl.ac.uk/~ucfagls/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list