Re: [R] listing all functions in R

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Tue 09 Jan 2007 - 15:29:03 GMT

"Earl F. Glynn" <efg@stowers-institute.org> writes:

> "Prof Brian Ripley" <ripley@stats.ox.ac.uk> wrote in message 
> news:Pine.LNX.4.64.0701061331420.8651@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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed Jan 10 08:10:46 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 10 Jan 2007 - 00:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.