[R] Packages: What expressions are allowed outside/before .First.lib?

Thomas Lumley tlumley at u.washington.edu
Thu Aug 9 19:06:14 CEST 2001


On Tue, 7 Aug 2001, Henrik Bengtsson wrote:


> 
> Q1. When loading pakages, if exists, the .First.lib function will be called
> in the end. Is it correct that it is only in .First.lib one should have
> "executable" code? Is it also true that "outside" .First.lib, only function
> declarations and objects assignments such as '.conflicts.OK <- TRUE' should
> be used?

I think it's fine to put any executable code in a package.  The RSMethods package does do some computation at install-time. There's some discussion of this and a mechanism to make it more efficient at
   http://developer.r-project.org/Install.html


> 
> Q3. After having used the attr() approach for a while, we wanted to add some
> control of the assignment of 'modifiers'. I wrote a function "modifiers<-"
> that assert that the values are valid before setting the attribute. Now the
> code would look like
> 
>   callMe0 <- function(x)
>     cat("hey\n")
>   modifiers(callMe0) <- c("private")
> 
>   callMe <- function(x)
>     callMe0(x)
>   modifiers(callMe) <- c("public")
> 
> I think this code is a little bit more readable, but bullet-proof in the
> sence that unknown modifiers can not be set. But, by doing this I know I am
> in deep water; to load this library I rely on the fact that "modifiers<-" is
> already declared. It looks like the library source file is created by
> concatenation the .R files in lexical order and one can force the
> declaration of "modifiers<-" to appear first by putting it in a file called
> "000.R" (zeros). However, I don't know if one can rely on this?!

It is not AFAICS documented, so we are not committed to it.  It is a consequence of the way Perl and/or the shell lists directories, so it is probably reliable. It also is the reason that .First.lib is typically put in a file called zzz.R

A simple, if inelegant, work-around is to concatenate the files yourself.
 
  -thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list