[R] Re: packaging a package addon

Thomas Lumley tlumley at u.washington.edu
Fri Oct 31 22:42:37 CET 2003


On Fri, 31 Oct 2003, Ross Boylan wrote:

> On Fri, 2003-10-31 at 06:41, A.J. Rossini wrote:
> > Ross Boylan <ross at biostat.ucsf.edu> writes:
> > >
> > > I also added library("survival") to my .First.lib.  Is library, rather
> > > than require, the right choice here?  I want it to fail if survival
> > > doesn't load.
> >
> > test the results from require, something like:
> >
> >      if (!require("survival")) stop("can't load survival")
> Doesn't using library do about the same thing?  What's the advantage of
> this, clearer diagnostics?
>


If you are going to fail when "survival" isn't found you should probably
just use library, though Tony's suggestion is effectively equivalent, and
I have also seen the Perly
   require(tcltk) || stop("error message")

The main point of require() is when failure isn't completely fatal: eg
hypothetically

if (!require(boot)) {
	warning("No `boot' package -- you're not getting confidence intervals")
	conf.int<-FALSE
}


	-thomas




More information about the R-help mailing list