[R] listing all functions in R

Earl F. Glynn efg at stowers-institute.org
Mon Jan 8 21:20:09 CET 2007


"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.

For example:

> findfuns("bcp")
Loading required package: bcp
Loading required package: DNAcopy
Error: package 'DNAcopy' could not be loaded
In addition: Warning message:
there is no package called 'DNAcopy' in: library(pkg, character.only = TRUE, 
logical = TRUE, lib.loc = lib.loc)

> require("bcp", character.only=TRUE)
Loading required package: bcp
Loading required package: DNAcopy
Error: package 'DNAcopy' could not be loaded
In addition: Warning message:
there is no package called 'DNAcopy' in: library(pkg, character.only = TRUE, 
logical = TRUE, lib.loc = lib.loc)


I used "try" around the "require" call with "options(error=recover)" with 
"recover" defined to be a do nothing function to avoid the stop, but then 
there were other problems (e.g., "unable to load shared library ... 
LoadLibrary Failure: The specified module could not be found" and "Maximal 
number of DLLs reached")

Besides "bcp" I saw problems with other packages, e.g., cairoDevice, 
caMassClass, ... several others.

I'm using R 2.4.1with all CRAN packages installed that existed last week and 
at least several Bioconductor packages installed by the biocLite procedure.

FWIW:
> length(pkgs)
[1] 957


Thanks for any suggestions.

efg

Earl F. Glynn
Scientific Programmer
Stower Institute



More information about the R-help mailing list