From ripley@stats.ox.ac.uk  Wed Oct 30 16:37:31 2002
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Wed, 30 Oct 2002 16:37:31 +0000 (GMT)
Subject: silent option for library function
In-Reply-To: <Pine.GSO.4.40.0210301112360.5730-100000@falmouth.bwh.harvard.edu>
Message-ID: <Pine.LNX.4.31.0210301632330.5214-100000@gannet.stats>

On Wed, 30 Oct 2002, Vincent Carey 525-2265 wrote:

Quoting me, anonymously!

> > BTW, there is no way for library() to control what a user does in his
> > .First.lib: he could put up a dialog box agreeing the usage terms.
> > Actually, that seems a rather good idea ....
>
> Indeed.  However, one could modify library to divert normal R
> output if a silent parameter were supplied.
>
> Thus if i edit library to incorporate a parameter silent=FALSE,
> and introduce the lines
>
> if (silent) sink("/dev/null")
> on.exit( if (silent) sink() )
>
> at the top of the function body, the command
>
> library(mgcv, silent=TRUE)
>
> has the desired silent behavior.  however, ordinary
> output is still diverted after the return from library(...)
> in this case!  perhaps I misunderstand
> the on.exit behavior.  I would expect that it would 'remove'
> the sink set in library and restore ordinary processing.

Try

if(silent) {
  sink("/dev/null")
  on.exit(sink())
}

as silent is not in scope at on.exit, I believe.

I have to say I think this is not a good idea.  People who want to put out
copyright notices at the top of their packages should be allowed to do so,
and we should not make it easy to suppress them.

(BTW none of mine do on R, although they do on S-PLUS at Insightful's
insistence.)

-- 
Brian D. Ripley,                  ripley@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-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


silent option for library function
ripley@stats.ox.ac.uk