Skip to content

Instantly share code, notes, and snippets.

@jkeirstead
Created September 4, 2013 13:57
Show Gist options
  • Save jkeirstead/6437289 to your computer and use it in GitHub Desktop.
Save jkeirstead/6437289 to your computer and use it in GitHub Desktop.
List all functions in a R source file
## List the functions in a file, or if not specified the global environment
##
## @param src an optional source file
##
## @return a character vector of function names
ls_functions <- function(src=NULL) {
if (is.null(src)) {
classes <- sapply(ls(.GlobalEnv), function(x) class(eval(parse(text=x))))
} else {
e <- new.env()
sys.source(src, env=e)
classes <- sapply(ls(e), function(x) class(eval(parse(text=x))))
}
return(names(which(classes=="function")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment