Created
May 15, 2014 04:08
-
-
Save kevinushey/d5e25a39e7ec97ddd276 to your computer and use it in GitHub Desktop.
Which function has the longest argument name?
This file contains hidden or 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
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