From PDalgd at gmail.com  Wed Jun 15 18:06:22 2011
From: PDalgd at gmail.com (peter dalgaard)
Date: Wed, 15 Jun 2011 18:06:22 +0200
Subject: [Rd] Loose code in R package files
In-Reply-To: <alpine.LFD.2.02.1106151514530.26318@gannet.stats.ox.ac.uk>
References: <BANLkTi=+=sr5Xa=_L9cFSj_fP0XiHgohsA@mail.gmail.com>
	<0D1AAABC-17B9-43A1-879D-3DA1BE7F4B51@r-project.org>
	<BANLkTinZSLr2uJXr63hA0ZRCkWstp5-wzA@mail.gmail.com>
	<98B156BB22D11342A931E823798D434852D599D392@GOLD.corp.lgc-group.com>
	<alpine.LFD.2.02.1106151514530.26318@gannet.stats.ox.ac.uk>
Message-ID: <AB67C4D9-AC51-4508-B4D4-5C6A8C254D66@gmail.com>


On Jun 15, 2011, at 16:22 , Prof Brian Ripley wrote:

> 
> So your example creates an object 'x' in the package or name space. Which is perfectly legal, but maybe not intentional.  For example, R's base package does
> ...

Yes. Nothing illegal about it, but might be worth noticing that if LazyLoading is used, then the object will be computed only once, while building the package. 

So "today <- date()" or "calibrate <- system.time(for(i in 1:1e6)...))" or is a bad idea unless you really want the value at build time on the build computer. 

Having results depending on whether or not LazyLoading is being used is probably not a good idea in any case. To have things happen on load, use .onLoad and relatives. 

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Loose code in R package files
peter dalgaard