[R] Selectively Removing objects

Greg Snow Greg.Snow at imail.org
Mon Feb 2 19:41:31 CET 2009

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

> -----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