Created
October 12, 2015 17:49
-
-
Save thirdwing/e6b6939d365d882865b2 to your computer and use it in GitHub Desktop.
ls functions
This file contains 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
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