[R] R package: Where to put code to Run Once Only?

Ken-JP kfmfe04 at gmail.com
Tue Apr 7 05:34:21 CEST 2009



Thanks to pointers from Uwe, I first tried zzz.R and .First.lib(), which
does what I needed (initialize once).

Then under Martin's suggestion, I converted the package to use NAMESPACE and
.onLoad().

Using NAMESPACE, I was able to hide my globals behind a "." (eg .myGlobal
<<- 72) and use exportPattern("^[^\\.]*") to prevent users from seeing my
globals, yet I was able to access their values inside my package.

After a couple of hours of cleaning up, I was able to tighten my package to
build cleanly (no warnings) for the first time in a long while with R CMD
Check - on 3 different machines.  I am happy to get no warnings on 2.8.1
(Ubuntu amd64) and 2.9 alpha (XP Pro 32 and Vista 32), where I learned
something new about RDoc Version 2 (the difference between \description and
\describe), changes going from 2.8.1 to 2.9.

So with a little persistence and a lot of assitance from R-help I was able
to tighten up the code and to build cleanly.  Thank you.


-- 
View this message in context: http://www.nabble.com/R-package%3A-Where-to-put-code-to-Run-Once-Only--tp22908592p22921596.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list