Created
December 31, 2013 09:19
-
-
Save rgrannell1/8194408 to your computer and use it in GitHub Desktop.
get the type signatures and parametres for an r package.
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
signify <- function (package) { | |
# environment -> [singatures: [string], params: [string]] | |
# gets the type-signature of every function in | |
# an environment, and every unique parameter. | |
data <- Map( | |
function (name) { | |
func <- get(name) | |
if (is.function(func)) { | |
list( | |
signature = paste(name, '<-', deparse(func)[1]), | |
params = names(formals(func)) ) | |
} else { | |
} | |
}, | |
ls(paste0('package:', package)) | |
) | |
sigs <- Reduce( | |
function (acc, new) { | |
acc$signatures <- | |
sort(c(acc$signatures, new$signature)) | |
acc$params <- | |
sort(union(acc$params, new$params)) | |
acc | |
}, | |
data, | |
list( | |
signatures = c(), | |
params = c() | |
) | |
) | |
lapply(sigs$signatures, function (x) cat(x, "\n")) | |
print(sigs$params) | |
invisible(NULL) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment