Re: [Rd] Top-level code in packages

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 03 Jul 2004 - 15:30:36 EST


On Fri, 2 Jul 2004, Frank E Harrell Jr wrote:

> Brian Ripley stated that in the future it will not be a good idea to
> have top-level code in R packages other than assignments. There is one
> important exception, though it leads instantly to an assignment. To
> maintain compatibility across multiple platforms (R, S-Plus, and more
> than one version of each, Windows, Linux, etc.) I frequently use if( )
> statements to conditionally define functions depending on the operating
> system and the version of R or S-Plus in effect.

That _is_ a top-level assignment. `Defining' a function is actually assigning a value to a symbol, and code inside if, for, etc is executed at top level.

I prefer to write

foo <- if(tools:::.OStype() == "windows") {...} else {...}

for conditional `definitions' precisely because it is clearer that is what is going on.

BTW, if you want to test the OS you can't do it with .Platform$OS.type and allow cross-building, hence the test illustrated.

-- 
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-devel@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
Received on Sat Jul 03 15:33:53 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 08:59:07 EST