Skip to content
Back to formatted view

Raw Message

Message-ID: <4DA4D94A.2080104@ucalgary.ca>
Date: 2011-04-12T22:59:22Z
From: Peter Ehlers
Subject: Removing objects and clearing memory
In-Reply-To: <OF920B0FB5.5E9F3305-ON88257870.007D622C-88257870.007DA0E8@epamail.epa.gov>

On 2011-04-12 15:52, Seeliger.Curt at epamail.epa.gov wrote:
>>>> How do I remove all objects except one in R?
>>>>
>>> rm(list=ls()) #will remove ALL objects
>>
>> But he wanted to remove all objects ***except one***!!!  So what's the
>> point of this answer?
>>
>> I can't see any way except a rather round-about kludge to do what the
>> OP wants. ...
>
> That might work.  Or try this, replacing QQQ with the name of the object
> you want to keep.
> rm(list=ls()[!grepl('^QQQ$',ls())])
>
> cur

package gdata has function keep() which does just what the OP asks for.

Peter Ehlers