[Rd] Wishlist: 'quietly' argument for .onAttach() / .First.lib()

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Apr 14 08:19:32 CEST 2006


I carefully did not suggest the use of option 'verbose', as that is used 
in many other places.  In particular, with your proposal, you cannot have 
the message without a lot of chatter from library() (and although that has 
a 'verbose' argument, it is often called implicitly, and rarely with 
that argument set).

Similarly for Bill Dunlap's proposal: suppressMessages would squelch all 
messages from the call, not just the one from your package's startup code.
Now, at present there may not be any, but that could well change as 
message() gets more widely used.

On Thu, 13 Apr 2006, Paul Roebuck wrote:

> On Thu, 13 Apr 2006, Liaw, Andy wrote:
>
>> From: Bill Dunlap
>>>
>>> On Thu, 13 Apr 2006, Prof Brian Ripley wrote:
>>>
>>>> On Thu, 13 Apr 2006, Peter Ruckdeschel wrote:
>>>>
>>>>> in "Writing R extensions" as well as in the help
>>>>> to .onAttach(), you mention that one could
>>>>> use this function to issue a start-up message/banner
>>>>> for the package.
>>>>>
>>>>> My little wish for Easter:
>>>>>
>>>>> a 'quietly'-type argument for .onAttach() / .First.lib() which is
>>>>> passed through by functions
>>>>> require() and library() respectively,
>>>>> and by means of which one could optionally
>>>>> suppress this start-up message/banner .
>>>>>
>>>>> Is this hard to do?
>>>>
>>>> I believe so (and think we have been here before).  The documented
>>>> call sequence is
>>>>
>>>>       .onLoad(libname, pkgname)
>>>>       .onAttach(libname, pkgname)
>>>>
>>>> the same as .First.lib.  There is no way to add an argument
>>> here, as
>>>> many existing packages do not support it.  Beyond that, how
>>> would you
>>>> pass the argument in?  Namespaces and packages are often
>>>> loaded/attached implicitly as a result of loading other packages.
>>>>
>>>> I did think you could make use of an option to decide
>>> whether to the
>>>> print the message or not, but I have always assumed that
>>> those who did
>>>> want a banner probably did not want it suppressed.
>>>
>>> If the .onAttach() used message() instead of cat()
>>> to display the banner message then you could use
>>> 	suppressMessages(require("randomForest"))
>>> to squelch the message.
>>
>> Thanks!  This looks like a good alternative.  What do others think of this
>> approach?
>
> I used an alternative approach myself. This allows the user
> enable/disable the banner text quite easily.
>
> .onAttach <- function(libname, pkgname) {
>    if (verbose <- getOption("verbose")) {
>        ...
>        desc <- packageDescription(pkgname)
>        cat(sprintf("%s, version %s", desc$Title, desc$Version), "\n")
>        cat(sprintf("Type library(help=%s) to see package documentation",
>                    libraryPkgName(pkgname)), "\n")
>    }
> }
>
> ----------------------------------------------------------
> SIGSIG -- signature too long (core dumped)
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list