Prof Brian Ripley
2004-Jul-01 15:39 UTC
[Rd] Top-level code in package files is not a good idea
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