[R] determining if a function exists in a particular package
William Dunlap
wdunlap at tibco.com
Fri Apr 27 23:45:20 CEST 2012
> 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.
More information about the R-help
mailing list