[R] listing all functions in R
Seth Falcon
sfalcon at fhcrc.org
Tue Jan 9 16:29:03 CET 2007
"Earl F. Glynn" <efg at stowers-institute.org> writes:
> "Prof Brian Ripley" <ripley at stats.ox.ac.uk> wrote in message
> news:Pine.LNX.4.64.0701061331420.8651 at gannet.stats.ox.ac.uk...
>> Here is a reasonable shot:
>>
>> findfuns <- function(x) {
>> if(require(x, character.only=TRUE)) {
>> env <- paste("package", x, sep=":")
>> nm <- ls(env, all=TRUE)
>> nm[unlist(lapply(nm, function(n) exists(n, where=env,
>> mode="function",
>> inherits=FALSE)))]
>> } else character(0)
>> }
>> pkgs <- dir(.Library)
>> z <- lapply(pkgs, findfuns)
>> names(z) <- pkgs
>
> Any recommendations on how to trap problems with "require" when using
> findfuns? One bad package and the lapply above doesn't return
> anything.
Are you sure you need to? I just tried your code above with:
pkgs <- c("Biobase", "GOstats", "flrblr", "bazbaz")
And while I see warning messages about the flrblr and bazbaz packages,
the function completed and I get the expected results in z.
Oh, perhaps you have some broken installs? Broken in the sense that
you have a package installed but not its dependencies?
How about this:
safeRequire <- function(x) {
tryCatch(require(x, character.only=TRUE),
error=function(e) FALSE)
}
And then replace the call to require in findfuns().
+ seth
More information about the R-help
mailing list