Skip to content

Instantly share code, notes, and snippets.

@njtierney
Created November 28, 2016 03:26
Show Gist options
  • Save njtierney/68b821c05cd724e26959bc9b76245426 to your computer and use it in GitHub Desktop.
Save njtierney/68b821c05cd724e26959bc9b76245426 to your computer and use it in GitHub Desktop.
f2 <- function(a, b, ...) {
a * 10
}
f2(10, stop("This is an error!"))
objs <- mget(ls("package:base"), inherits = TRUE)
funs <- Filter(is.function, objs)
is_not_primitive <- function(x){
is.primitive(x) == FALSE
}
funs_not_prim <- Filter(is_not_primitive, funs)
length(funs_not_prim)
length(names(funs_not_prim))
df_funs <- data_frame(fun_name = names(funs_not_prim),
funs = funs_not_prim)
df_fun_count <- df_funs %>%
mutate(
fun_count = purrr::map_int(.x = funs,
.f = function(x) length(formals(x)))
)
df_fun_count %>%
filter(fun_count == 0) %>% View()
formals(funs[[2]])
names(objs)
funs[[1]]
fun_is_prim <- (purrr::map_lgl(funs, is.primitive))
df_funs %>%
mutate(
length_args = purrr::map_df(.x = funs,
.f = function(x) length(formals(x)))
)
length_args <- purrr::map_df(.x = funs,
.f = function(x) length(formals(x)))
length(length_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment