Skip to content

Instantly share code, notes, and snippets.

@kevinushey
Created May 15, 2014 04:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinushey/d5e25a39e7ec97ddd276 to your computer and use it in GitHub Desktop.
Save kevinushey/d5e25a39e7ec97ddd276 to your computer and use it in GitHub Desktop.
Which function has the longest argument name?
for (package in installed.packages()[, 1])
library(package, character.only = TRUE)
ns <- search()
output <- vector("list", length(ns))
for (i in seq_along(output)) {
namespace <- ns[[i]]
env <- as.environment(namespace)
objs <- mget(
objects(envir = env),
env
)
if (!length(objs)) next
funs <- objs[sapply(objs, is.function)]
formals <- lapply(funs, function(x) {
names(formals(x))
})
len <- lapply(formals, function(x) {
setNames(nchar(x), x)
})
all_arg_lengths <- sort(((unlist(unname(len)))))
output[[i]] <- all_arg_lengths
}
tail(sort(unlist(output)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment