Skip to content

Instantly share code, notes, and snippets.

@thirdwing
Created October 12, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thirdwing/e6b6939d365d882865b2 to your computer and use it in GitHub Desktop.
Save thirdwing/e6b6939d365d882865b2 to your computer and use it in GitHub Desktop.
ls functions
find.funs <-function(pos = 1, ..., exclude.mcache = TRUE, mode = 'function') {
findo <- function(pos2) {
o <- named(lsall(pos = pos2, ...))
if (!length(o))
return(character(0))
# keep if exists
keep <- sapply(o, exists, where = pos2, mode = mode, inherits = FALSE)
if (!any(keep))
return(character(0))
names(o) <- NULL
o[keep]
}
# make sure we are finding functions in R environments
if (is.environment(pos))
pos <- list(pos)
else
pos <- lapply(pos, as.environment)
unlist(lapply(pos, findo), use.names = FALSE)
}
named <- function (x) {
if (!length(x))
return(x)
names(x) <- as.character(x)
x
}
lsall <- function(...) {
mc <- match.call(expand.dots = TRUE)
mc$all.names <- TRUE
mc[[1]] <- as.name('ls')
eval(mc, parent.frame())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment