Dear all: a quick question: I am used to apply rm(list=()) regularly to remove all old codes in preventing them creeping in current analysis.however, with that application, functions I wrote are also removed. please let me know how to keep the thing you want while remove those you don't. thank you best yong
Henrik Bengtsson
2004-Jan-25 09:21 UTC
[R] how to keep functions while remove all other commands
Hi, it's not clear what you asking for, but if you want to remove all object except functions here's the shortest one-line solution that I can think of rm(list=ls()[!sapply(ls(), FUN=exists, mode="function")]) Henrik Bengtsson Lund University, Sweden> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Yong Wang > Sent: den 25 januari 2004 04:47 > To: r-help-request at stat.math.ethz.ch > Cc: r-help at stat.math.ethz.ch > Subject: [R] how to keep functions while remove all other commands > > > Dear all: > a quick question: > I am used to apply rm(list=()) regularly to remove all old codes in> preventing them creeping in current analysis.however, with that > application, functions I wrote are also removed. please let > me know how to keep the thing you want while remove those you don't. > > thank you > > best > yong > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailma> n/listinfo/r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Petr Pikal
2004-Jan-26 09:32 UTC
[R] how to keep functions while remove all other commands
Hi On 24 Jan 2004 at 21:47, Yong Wang wrote:> Dear all: > a quick question: > I am used to apply rm(list=()) regularly to remove all old codes in > preventing them creeping in current analysis.however, with that > application, functions I wrote are also removed. please let me know > how to keep the thing you want while remove those you don't.I usually work in some separate home directory (e.g. D:\data\stat\standard) and I store my functions I want to keep in another directory (D:\prog\R\......\library\fun), which can be attached as any other library in the same way like other libraries can. You just have to use some files (I think at least INDEX and DESCRIPTION). More in "R-exts" manual. Cheers Petr> > thank you > > best > yong > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
Simon Fear
2004-Feb-02 09:42 UTC
[R] how to keep functions while remove all other commands
As an alternative to Petr's approach of using separate directories, one can also write a function (which I find quite useful in its own right) to separate ls() output by mode, e.g. "lsd" <- function(splitby=mode, pos=1, ...) { lsout <- ls(pos=pos, ...) tapply(lsout, sapply(lsout, function(x) {splitby(get(x))}), invisible) } Given that, you can use expressions such as rm(list=lsd()$numeric) rm(list=lsd(splitby=class, all.names=T)$integer) or to remove functions, rm(list=lsd()$"function") # nb reserved word function needs quotes this latter also removes `lsd` itself, so do also follow the advice re keeping a copy of all your functions in a text file somewhere!> -----Original Message----- > On 24 Jan 2004 at 21:47, Yong Wang wrote: > > > Dear all: > > a quick question: > > I am used to apply rm(list=()) regularly to remove all old codes in > > preventing them creeping in current analysis.however, with that > > application, functions I wrote are also removed. please let me know > > how to keep the thing you want while remove those you don't. >Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}