2011-02-24 98 views
19

可能重复:
Is there a way to get a vector with the name of all functions that one could use in R?获取R中的全球环境中加载的功能列表

我想来自R得到的加载函数列表环境。
我知道ls(),它给出了加载对象的列表。但有些对象不是功能。
我想从函数中清理我的env,而不是从包含我不希望丢失的结果的其他对象(矩阵,数组等)中清除我的env。

有什么想法?

+2

重复http://stackoverflow.com/q/4267744/429846? – 2011-02-24 10:41:23

+0

不,stackoverflow.com/q/4267744/429846是来自包的函数,我在说ls中的函数() – RockScience 2011-02-24 10:50:18

+0

我没有注意到,但是,是的,它是重复的。曾经尝试过那里的解决方案?哎呀,我只是意识到我甚至给出了完全相同的答案。 – 2011-02-24 11:03:40

回答

26

?lsf.str

X <- lsf.str() 
as.vector(X) # just for printing purposes, you can use the vector in rm() 
rm(list=X) 
+0

变化:'c(lsf.str())' – 2011-02-24 15:11:37

+0

@G。格洛腾迪克:或将所有内容组合为'rm(list = lsf.str())' – 2011-02-24 15:23:28

1

好吧,我有一个提议

rm(list=ls()[sapply(ls(), function(obj) "function"==class(eval(parse(text = obj)))[1])]) 

我相信有一些更优雅。