Erin Hodgess
2012-Apr-27 21:07 UTC
[R] determining if a function exists in a particular package
Hello R People: Is there a way to determine if a function exists in a particular package, please? I looked at exists and objects, but they seem to refer to an environment rather than a package. I was thinking of something like: ifelse(exists(functiona) in MASS, print(1:10), print(5)) Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com
Erin Hodgess
2012-Apr-27 21:13 UTC
[R] determining if a function exists in a particular package
I found the solution in an old post: It's lsf.str("package:ts") for functions. Cool! On Fri, Apr 27, 2012 at 4:12 PM, Mark Leeds <markleeds2 at gmail.com> wrote:> Hi Erin: I don't know how to do it programatically but it might be quicker > to just > go to the vignette and click on it. All the functions should be in the right > column of > the pdf. Of course, you may have reason for needing it programatically in > which > case, my apologies for the noise !!!!! > > On Fri, Apr 27, 2012 at 5:07 PM, Erin Hodgess <erinm.hodgess at gmail.com> > wrote: >> >> Hello R People: >> >> Is there a way to determine if a function exists in a particular >> package, please? >> >> I looked at exists and objects, but they seem to refer to an >> environment rather than a package. >> >> I was thinking of something like: >> >> ifelse(exists(functiona) in MASS, print(1:10), print(5)) >> >> 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. > >-- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com
William Dunlap
2012-Apr-27 21:45 UTC
[R] determining if a function exists in a particular package
> I looked at exists and objects, but they seem to refer to an > environment rather than a package.Those functions work with the names of attached packages, but you have know that the name of an attached package has "package:" prefixed to the package's usual name. E.g., > exists("lm", "package:stats") [1] TRUE > objects("package:stats", pattern="iso") [1] "isoreg" If you leave off the "package:" you might be misled into thinking an environment is required: > objects("stats", pattern="iso") Error in as.environment(pos) : no item called "stats" on the search list Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of Erin Hodgess > Sent: Friday, April 27, 2012 2:08 PM > To: R help > Subject: [R] determining if a function exists in a particular package > > Hello R People: > > Is there a way to determine if a function exists in a particular > package, please? > > I looked at exists and objects, but they seem to refer to an > environment rather than a package. > > I was thinking of something like: > > ifelse(exists(functiona) in MASS, print(1:10), print(5)) > > 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.