Search code examples
rfunctionworkspace

Finding all functions in current workspace


I'd like to find all functions in my current workspace and thought about using is.function for that purpose.

The "problem" is that is.function expects a true R object, not the character string name of an object.

That's my solution, but using eval(substitute(...)) seems a bit involved. Any ideas for a more straight forward way or is that the only way this can be done?

Example content

x <- TRUE
y <- 10
foo1 <- function() message("hello world!")
foo2 <- function() message("hello world again!")

Finding all function objects

wscontent <- ls(all.names=TRUE)
funs <- sapply(wscontent, function(ii) {
    eval(substitute(is.function(OBJ), list(OBJ=as.name(ii))))
})
> funs
     foo1      foo2      funs wscontent         x         y 
     TRUE      TRUE     FALSE     FALSE     FALSE     FALSE 

Solution

  • How about

    lsf.str()
    

    which should list all functions.