5

I'm loading optmatch in a Sweave document as follows:

<<myCodeBlock, echo=FALSE>>=
library(optmatch, quietly=TRUE)
@

You're loading optmatch, by Ben Hansen, a package for flexible
and optimal matching. Important license information:
The optmatch package makes essential use of D. P. Bertsekas
and P. Tseng's RELAX-IV algorithm and code, as well as
Bertsekas' AUCTION algorithm and code.
Bertsekas and Tseng freely permit their software to be used for
research purposes, but non-research uses, including the use of it
to 'satisfy in any part commercial delivery requirements to
government or industry,' require a special agreement with them.
By extension, this requirement applies to any use of the
fullmatch() function. (If you are using another package that has
loaded optmatch, then you will probably be using fullmatch indirectly.)
For more information, enter relaxinfo() at the command line

As you can see, I've tried every way I can think of to silence the package load message, to no avail. I assume this is because they just used a straight-up cat() or something like that, but it's mighty annoying. Any thoughts on how to silence this so that those reading my final, beautiful, LaTeXified PDF don't have to read about RELAX-IV?

Other things that don't seem to work (take from Andrie's pointer to a related thread):

suppressMessages(library(optmatch))
suppressPackageStartupMessages(require("optmatch"))

I should note this is pretty obviously an R problem not a Sweave problem, as the messages pop up in R also.

Community
  • 1
  • 1
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
  • 1
    I believe this question has the answer: http://stackoverflow.com/q/6279808/602276 – Andrie Nov 15 '11 at 21:27
  • Thanks! Super helpful. But neither of those works either, amazingly enough. Thought for sure `suppressMessages` would. – Ari B. Friedman Nov 15 '11 at 21:38
  • 1
    I suggest you contact the author(s) on this kind of non-standard startup messages; `cat()` should be avoided in `.onLoad()`. The standard practice should be `packageStartupMessage()`, which can be suppressed by `suppressPackageStartupMessages()`; for `cat()`, we have to use all sorts of dirty tricks to hide the messages. – Yihui Xie Nov 16 '11 at 03:09
  • Re-tagging with [tag:knitr], since the solutions I've tested appear to work identically across both `Sweave` and `knitr`. – Ari B. Friedman Jan 28 '13 at 15:55
  • See my rant "watch out your cats" here: http://yihui.name/knitr/demo/output/ :) – Yihui Xie Jan 28 '13 at 17:39
  • @Yihui I actually found that post and tried `echo=FALSE,results='hide',messages=FALSE` before I came here today. `xtable` was not amenable, but it yielded to `suppressMessages()`. But I'd forgotten that I'd quoted the `hide` part :-) – Ari B. Friedman Jan 28 '13 at 17:40
  • 1
    @AriB.Friedman interesting... if you want to kill everything, you can simply `include=FALSE` – Yihui Xie Jan 28 '13 at 17:48
  • @Yihui Excellent. I usually have a load packages block at the top of my document, so `include=FALSE` looks perfect. – Ari B. Friedman Jan 28 '13 at 18:03

2 Answers2

7

Try loading the package in a hide results chunk:

<<packages,results=hide>>= 
require(optmatch) 
@

If you use the knitr package, you need to quote hide:

<<packages,results='hide'>>= 
require(optmatch) 
@
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
Xu Wang
  • 10,199
  • 6
  • 44
  • 78
3

Here is an R solution to your problem. The package author uses cat to print the messages to the console, rather than using standard message statements. You can intercept these messages by using sink to divert console output to a temporary file:

<<myCodeBlock, echo=FALSE>>=
zz <- tempfile()
sink(file=zz)
library(optmatch, quietly=TRUE))
unlink(zz)
@

PS. The solution by @XuWang uses only SWeave, so is clearly much more suitable in your case.

Andrie
  • 176,377
  • 47
  • 447
  • 496