Skip to content

Instantly share code, notes, and snippets.

@rgrannell1
Created December 31, 2013 09:19
Show Gist options
  • Save rgrannell1/8194408 to your computer and use it in GitHub Desktop.
Save rgrannell1/8194408 to your computer and use it in GitHub Desktop.
get the type signatures and parametres for an r package.
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