Created
September 4, 2013 13:57
-
-
Save jkeirstead/6437289 to your computer and use it in GitHub Desktop.
List all functions in a R source file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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