would it be possible to add an option to library that prevents messages except when there are errors? as we build Sweave documents illustrating package functionalities it is sometimes desirable to attach a package "behind the scenes". packages that have messages emitted in .First.lib (often describing version or developer) frustrate this particular desire. verbose=FALSE does not accomplish this. note that i have no objection to messages produced by default use of library. i just want the ability to suppress them when there are no errors. currently it is possible to do sink(file="/dev/null") library([e.g. affy]) sink() but that may suppress too much -- an error message may be lost. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 30 Oct 2002, Vincent J. Carey, Jr. wrote:> would it be possible to add an option to library that > prevents messages except when there are errors? as > we build Sweave documents illustrating package functionalities > it is sometimes desirable to attach a package "behind > the scenes". packages that have messages emitted > in .First.lib (often describing version or developer) > frustrate this particular desire. verbose=FALSE > does not accomplish this. > > note that i have no objection to messages produced by > default use of library. i just want the ability to > suppress them when there are no errors. currently > it is possible to do > > sink(file="/dev/null") > library([e.g. affy]) > sink() > > but that may suppress too much -- an error message may be > lost.Don't think so. From help(sink): Normal R output is diverted by the default `type = "output"'. Only prompts and warning/error messages continue to appear on the terminal. These too can diverted by `type = "message"' (see below). and for example> sink(file="/dev/null") > library(foo)Error in firstlib(which.lib.loc, package) : testing Error in library(foo) : .First.lib failed> sink()So how are you losing error messages? 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 .... -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> Vincent J Carey, writes:> would it be possible to add an option to library that > prevents messages except when there are errors? as > we build Sweave documents illustrating package functionalities > it is sometimes desirable to attach a package "behind > the scenes". packages that have messages emitted > in .First.lib (often describing version or developer) > frustrate this particular desire. verbose=FALSE > does not accomplish this.> note that i have no objection to messages produced by > default use of library. i just want the ability to > suppress them when there are no errors. currently > it is possible to do> sink(file="/dev/null") > library([e.g. affy]) > sink()> but that may suppress too much -- an error message may be > lost.The QA tools use the following: .loadPackageQuietly <- function(package, lib.loc) { ## Load (reload if already loaded) @code{package} from ## @code{lib.loc}, capturing all output and messages. All QA ## functions use this for loading packages because R CMD check ## interprets all output as indicating a problem. outConn <- textConnection("out", "w") sink(outConn, type = "output") sink(outConn, type = "message") yy <- try({ pos <- match(paste("package", package, sep = ":"), search()) if(!is.na(pos)) detach(pos = pos) library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) }) if(inherits(yy, "try-error")) stop(yy) sink(type = "message") sink(type = "output") close(outConn) } -k -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._