[R] Selectively Removing objects

Paulo Grahl pgrahl at gmail.com
Mon Feb 2 20:47:39 CET 2009

Thanks Greg.
I did in the past looked into the details of how to create a package.
I did not seem too complicated, but it would be time consuming -- an
then when one thinks in creating a package (even for his own use)  it
always a good idea to check for wrong inputs, to have all functions
well documented, etc. The functions I've developed so far are not yet
in this stage.

But i liked the idea of using attach(). I had overlooked this point in
the attach() description.

Paulo Gustavo Grahl, CFA

On Mon, Feb 2, 2009 at 4:41 PM, Greg Snow <Greg.Snow at imail.org> wrote:
> If you want to keep the functions, why not move them to a different environment so that they don't get deleted when you delete everything else (this will also work better if you want to use these same functions in other R sessions).
> The most comprehensive way to do this is to create a package with the functions (package.skeleton will get you started).
> One of the simplest ways to do this (if the package idea is overkill, though if you expand this, the package solution may not be overkill in the long run) is to use the 'save' command to save your functions into a file, delete everything including the functions, then use 'attach' to attach the file you saved the functions in.  Now you can still use the functions (just be careful if you try to edit them), but they are not in the main environment where the data is stored and when you delete 'everything' the next time, the attached functions will not be affected.
> Hope this helps,
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at imail.org
> 801.408.8111
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Paulo Grahl
>> Sent: Monday, February 02, 2009 6:17 AM
>> To: r-help at r-project.org
>> Subject: [R] Selectively Removing objects
>> Dear list members,
>> Does anyone know how to use rm() to remove only variables but not
>> declared functions from the environment ?
>> I understand I could name all the functions with, let's say
>> "f_something", make sure that all variables do not start with "f_" and
>> then remove all BUT objects starting with "f_".
>> However, I have already defined all the functions and it would be
>> troublesome to change all of them to a new name.
>> Any hint ?
>> Thanks
>> Paulo Gustavo Grahl, CFA
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list