Re: [R] listing all functions in R

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

"Earl F. Glynn" <> writes:

> "Prof Brian Ripley" <> wrote in message 

>> 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 mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.