[R] testing the contents of an environment

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Sep 28 01:38:10 CEST 2007


On 9/27/07, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>
> On 28/09/2007, at 6:52 AM, Tim Bergsma wrote:
>
> > Suppose I want to delete everything in my working directory that is
> > not
> > a function. It seems that
> >
> > sapply(ls(),is.function)
> >
> > always returns FALSE, because ls() returns objects of mode character.
> > How do I evaluate is.function(), not on a character string, but on the
> > object that character string represents?
>
> sapply(ls(),function(x){is.function(get(x))})

A conceptually simpler alternative is

sapply(ls(), exists, mode = "function", inherits = FALSE)

-Deepayan



More information about the R-help mailing list