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

Prof Brian D Ripley ripley at stats.ox.ac.uk
Thu Aug 9 21:23:39 CEST 2001


On Thu, 9 Aug 2001, Thomas Lumley wrote:

> 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

*We* rely on it, though, to ensure that New-Internals.Rd comes high up in
base.  There is a potential problem!  What happens is

 $(srcdir)/R/*.R $(srcdir)/R/unix/*.R >> $${f};

so that sorts files lexicographically *in the current locale*, whatever
sh thinks that is.  We (e.g. nlme. models) use AAA.R which is (sort
of) guaranteed to come above b-z, B-Z (but might come after a, and does
in en_US on Solaris).

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

Agreed.

Brian

-- 
Brian D. Ripley,                  ripley at 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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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