remove all variables except functions

后端 未结 5 1427
耶瑟儿~
耶瑟儿~ 2020-12-12 09:43

I have loaded in a R console different type of objects. I can remove them all using

rm(list=ls())

or remove only the functions (but not the

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 10:19

    The posted setdiff answer is nice. I just thought I'd post this related function I wrote a while back. Its usefulness is up to the reader :-).

    lstype<-function(type='closure'){ 
        inlist<-ls(.GlobalEnv)
        if (type=='function') type <-'closure'
        typelist<-sapply(sapply(inlist,get),typeof)
        return(names(typelist[typelist==type]))
    }
    

提交回复
热议问题