[R] listing all functions in R

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Jan 6 14:48:15 CET 2007


Could you tell us what you mean by

- 'function'  (if() and + are functions in R, so do you want those?)

- 'a base R installation'?   What is 'base R' (standard + recommended 
packages?)  And on what platform: the list is platform-specific?

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

I don't understand your desired format, but

write(sQuote(sort(unique(unlist(z)))), "")

gives a single-column quoted list.  It does include internal functions, 
operators, S3 methods ... so you probably want to edit it.


On Sat, 6 Jan 2007, Gavin Simpson wrote:

> Dear List,
>
> I'm building an R syntax highlighting file for GeSHi [*] for a website I
> am currently putting together. The syntax file needs a list of keywords
> to highlight. How can I generate a list of all the functions in a base R
> installation?
>
> Ideally the list would be formatted like this:
>
> "'fun1', 'fun2', 'fun3'"
>
> when printed to the screen so I can copy and paste it into the syntax
> file.
>
> I'm sure this has been asked before, but I stupidly didn't save that
> email and I couldn't come up with a suitable query parameter for
> Jonathan Baron's search site to return results before timing out.
>
> Thanks in advance,
>
> Gav
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list