|
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: [hidden email] ______________________________________________ [hidden email] 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. |
|
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 <[hidden email]> 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 <[hidden email]> > 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: [hidden email] >> >> ______________________________________________ >> [hidden email] 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: [hidden email] ______________________________________________ [hidden email] 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. |
|
You can also use exists():
> library(MASS) > exists("loglm", where=search()[grepl("MASS", search())]) [1] TRUE > exists("loglmx", where=search()[grepl("MASS", search())]) [1] FALSE As for lsf.str(), this only works for loaded packages. You didn't specify whether you needed to be able to search loaded packages, installed packages, or packages that exist on CRAN. Package sos might be helpful for the last of those; you can use help.search and grep to search for functions within installed but unloaded packages. Since you didn't tell us anything about your objectives, it's impossible to know what you are really looking for. Sarah On Fri, Apr 27, 2012 at 5:13 PM, Erin Hodgess <[hidden email]> wrote: > 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 <[hidden email]> 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 <[hidden email]> >> 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 >>> -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ [hidden email] 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. |
|
In reply to this post by Erin Hodgess-2
On Fri, Apr 27, 2012 at 5:13 PM, Erin Hodgess <[hidden email]> wrote:
> I found the solution in an old post: > > It's > lsf.str("package:ts") > > for functions. > > Cool! > Note that that gives exported functions. If you also want internal functions in addition to the exported ones then try this: library(ts) lsf.str(asNamespace("ts")) Also note that these not give functions whose name starts with dot unnless all.names=TRUE is added as an argument. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ [hidden email] 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. |
|
In reply to this post by Erin Hodgess-2
> 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: [hidden email] [mailto:[hidden email]] 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: [hidden email] > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] 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. |
| Powered by Nabble | Edit this page |
