Re: [R] How to get the namespace of a function?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 03 Feb 2006 - 18:30:11 EST

On Thu, 2 Feb 2006, Fernando Saldanha wrote:

> I am trying to imitate "encapsulation" from other languages like Java
> or C++. Coming from that background, it bothers me that I can commit
> errors like the following:
>
>> x <- 1
>> f <- function(z) { y <- x; y + 1 } # Mistake: I should have written y <- z
>> f(10)
> [1] 2
>
> In a language like Java the interpreter would have noticed that x was
> an undeclared variable and an error message would be issued. R, on the
> other hand, allows the code to run, as x exists in the global
> environment. I was trying to avoid such situations by setting the
> environment of f to be NULL. If there is a better way to catch this
> type of errors I would be interested in knowing about it.

The codetools package. See http://www.stat.uiowa.edu/~luke/R/codetools.

(They are not R errors, but the codetools package can tell you that 'x' is not necessarily in scope.)

-- 
Brian D. Ripley,                  ripley@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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Feb 03 18:43:55 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:21 EST