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

Paul Roebuck roebuck at mdanderson.org
Sat Apr 15 09:41:18 CEST 2006


On Fri, 14 Apr 2006, Prof Brian Ripley wrote:

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

Fair enough. 'Course I preferred the implicit 'quietly' argument
so the 'verbose' option works perfectly in that case. Possibly a
minority view on the subject, but I don't care for packages being
"chatty" myself except when explicitly asked to be so by the user.

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

I found Bill's suggestion a bit scary myself; suppressing messages
when dealing with loading packages seems a bit like disabling the
compiler's warning messages - a bad idea. But it was a novel approach.

Given what you said above, do you favor the suggestion to use
message() instead of cat() for the purpose of .onAttach() startup
messages? I've seen message() before in the manpages but never saw
any documentation on how or when it might be considered appropriate
to use. Why would one want to represent a simple non-error message
as a condition in the first place?


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



More information about the R-devel mailing list