[R] Defining/Checking constants in packages

Deepayan Sarkar deepayan at stat.wisc.edu
Wed Nov 20 23:43:21 CET 2002

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.)

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

More information about the R-help mailing list