[R] Is there an easier way than this to list all functions in the global environment?
Byron Dom
byron_dom at yahoo.com
Mon May 19 00:49:48 CEST 2014
After an unsuccessful search thru several books plus online documentation, I was unable to find a simple way to do this, so I wrote my own function (see below) to do it. I'm relatively new to R however, so I'm guessing that there must be an easier way to do it.
I want to list all functions and only the functions (not other objects also) in the global environment.
I'm working with several old R workspaces that contain a very large number of objects -- functions, data structures, etc. and I would to be able to easily find out which objects are functions.
The function below (listfunc()) works fine. I'm just asking this for future reference.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
listfunc <- function() {
# lists names of all function objects in the global environment
obj <- objects(.GlobalEnv)
funclist <- character(length = 0)
for (i in 1:length(obj)) {
if (mode(get(obj[i])) == "function") funclist <- c(funclist,obj[i])
}
return(funclist)
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
More information about the R-help
mailing list