[R] options --- na.rm , save-on-exit

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Jul 3 20:07:37 CEST 2004


On Sat, 3 Jul 2004, Spencer Graves wrote:

>       I presume by "no" Uwe means that there is apparently nothing as 
> simple as changing "na.rm" to TRUE in "options". 
> 
>       However, you could redefine the functions "mean" and "median" so 
> the default was "na.rm=TRUE".  That's easy to do with median:  Type 
> "median" at a command prompt, copy the result to a script file, modify 
> it, and source it.  You could also build your own package and attach it 
> in a leading position in your search path so your version of median, 
> etc., got used instead of the system version.  Doing this with "mean" is 
> harder, because is a generic function, which means that you would need 
> to know how to modify generic functions. 
> 
>       I would not recommend this.  To take an extreme analogy, I'm 
> reminded of the old joke about a state senator in the sovereign state of 
> __________ (you pick it), who declared that 3.14, etc., was too hard for 
> school children to learn, and it school would be easier if pi were 3.  
> He therefore introduced legislation to make pi = 3 (in his state, of 
> course).  You can do that in R, just by typing "pi <- 3" at any command 
> prompt.  However, it might have unintended consequences. 

In this case, it may not have the intended consequence.  mean (and to a 
lesser extent median) is widely used by R itself, and namespaces make sure 
that most of those uses will ignore your redefinitions.  So please don't 
redefine system functions, but rather define your own like medianNoNA.
Then only you get affected, and in particular the R-helpers don't have to 
second guess what you have done several months later when you forget about 
the change.

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




More information about the R-help mailing list