[Rd] Top-level code in package files is not a good idea

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu 01 Jul 2004 - 18:19:46 EST


It is not a good idea to have executable code other than assignments in R code files in packages. (The most common example is to require() some other package.) Doing so presumes that the R code will be sourced when the package is loaded, and this is not true when saved images are used or with the databases of saved objects that we are testing for R 2.0.0.

The following packages fail under tests of an experimental version of R because of top-level require()s

    DCluster SASmixed agce cramer forward gridBase hier.part its multidim     pcurve phyloarray sandwich

Please put code that should be executed when the package is loaded in a .First.lib function, or for package with a namespace in a .onLoad function (or import another namespace in the namespace). And if you are using require(), you should test its value and act appropriately if the package is not available (even if it is a standard package, as we do sometimes rename those).

This is not urgent (the databases of saved objects are not expected to be released until October, and then will be optional for packages and probably not the default), but please bear this in mind.

-- 
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 Thu Jul 01 23:43:09 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:00 EST