Skip to content
Prev 43521 / 398513 Next

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