On Thu, 13 Apr 2006, Paul Roebuck wrote:
On Thu, 13 Apr 2006, Liaw, Andy wrote:
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
many existing packages do not support it. Beyond that, how
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
print the message or not, but I have always assumed that
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")
}
}