[R] Selectively Removing objects

Paulo Grahl pgrahl at gmail.com
Mon Feb 2 14:57:33 CET 2009


Thank you all for the prompt answer !!
It did solve my problem perfectly !
Rgds,
Paulo





On Mon, Feb 2, 2009 at 11:51 AM, Kenn Konstabel <lebatsnok at gmail.com> wrote:
> You can get a list of all functions in your workspace with
>
> ls()[sapply(ls(), function(x) is.function(get(x)))]
> # or   ls()[sapply(sapply(ls(), get), is.function)]
>
> Removing everything else is
>
> rm(list=ls()[sapply(ls(), function(x) !is.function(get(x)))])
> # or   rm(list=ls()[!sapply(sapply(ls(), get), is.function)])
> That suffices if you don't have any names starting with .period; if you do,
> you'll need ls(all=TRUE)
>
> KK
>
> On Mon, Feb 2, 2009 at 3:16 PM, Paulo Grahl <pgrahl at gmail.com> wrote:
>>
>> 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