"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