[R] Defining/Checking constants in packages
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Thu Nov 21 08:40:59 CET 2002
On Wed, 20 Nov 2002, Deepayan Sarkar wrote:
>
> Although namespaces are not fully implemented yet, the base namespace does
> work in R 1.6.x. e.g.,
>
> > pi <- 90
> > pi
> [1] 90
> > base::pi
> [1] 3.141593
>
> (Of course, there might be other ways as well.)
> get("pi", envir=.GlobalEnv)
[1] 3.141593
is equivalent and works in all versions of R. Just use it, rather than
assigning the value.
>
> On Wednesday 20 November 2002 03:39 pm, Giovanni Petris wrote:
> > In a package I am writing I need to use the constant pi (3.14..., that
> > is) which is already defined in R. However, how can I make sure the
> > user has not changed its value before loading the package?
> > If this happened, is a reference to `pi' in the package going to use
> > the user-defined value or the value defined in base?
> > I thought I could solve the issue by including the following line in
> > my package
> > pi <- get("pi", pos=grep("package:base",search()))
> > but then when I load the package R warns me about masking issues.
> > What is the recommended way of dealing with this issue?
> >
> > Thank you in advance,
> > Giovanni
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list