获取R的全局环境中加载的函数列表[重复]

时间:2023-01-19 23:35:10

Possible Duplicate:
Is there a way to get a vector with the name of all functions that one could use in R?

可能重复:有没有办法获得一个可以在R中使用的所有函数名称的向量?

Hi

你好

I would like to get from R the list of functions loaded in the environment.
I know ls() that gives the list of objects loaded. But some objects are not functions.
I would like to clean my env from the functions but not from the other objects (matrices, array etc) that contain some of my result that dont want to lose.

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

Any idea?

任何想法?

2 个解决方案

#1


27  

See ?lsf.str

见?lsf.str

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

#2


1  

ok, I have a proposal

好的,我有一个建议

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

I am sure there is something more elegant.

我相信有更优雅的东西。

#1


27  

See ?lsf.str

见?lsf.str

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

#2


1  

ok, I have a proposal

好的,我有一个建议

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

I am sure there is something more elegant.

我相信有更优雅的东西。