Dear R People: Is there a way to find which objects are functions via ls(), please? I'm sure that there is, but I'm not sure how. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com
ls()[sapply(ls(), function(x) is.function(get(x)))] On Fri, Dec 17, 2010 at 12:12 PM, Erin Hodgess <erinm.hodgess@gmail.com>wrote:> Dear R People: > > Is there a way to find which objects are functions via ls(), please? > > I'm sure that there is, but I'm not sure how. > > Thanks, > Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodgess@gmail.com > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
?ls.str ls.str(mode='function') On Fri, Dec 17, 2010 at 12:12 PM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:> Dear R People: > > Is there a way to find which objects are functions via ls(), please? > > I'm sure that there is, but I'm not sure how. > > Thanks, > Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodgess at gmail.com > > ______________________________________________ > R-help at r-project.org 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
On 17/12/2010 12:12 PM, Erin Hodgess wrote:> Dear R People: > > Is there a way to find which objects are functions via ls(), please? > > I'm sure that there is, but I'm not sure how. >Besides the solution you already have, take a look at ?lsf.str. Duncan Murdoch
Oddly enough, I posted my little cutie recently: lstype<-function(type='closure'){ # inlist<-ls(.GlobalEnv) if (type=='function') type <-'closure' typelist<-sapply(sapply(inlist,get),typeof) return(names(typelist[typelist==type])) } And, not useful for functions, but to find the size of a pile of data objects, thefloats<-lstype('numeric') sapply(sapply(sapply(sapply(thefloats,get),unlist),as.vector),length)