On 6 February 2010 at 13:06, Yaroslav Halchenko wrote:
| Hi Laurent and all, all, all,
| Does anyone know any RPy2-friendly way to shut R up while I try to load
| libraries? I just want some exception to be through without junk to be
| present on std* ...
| here is what I am talking about:
| In : rpy2.__version__
| Out: '2.0.8'
| so if I do
| import rpy2.robjects
| r = rpy2.robjects.r
| I get
| Loading required package: Matrix
| Loading required package: lattice
| which I do not want to appear under no circumstances (makes doctesting ugly
| etc), so I came up with a dirty hack:
| # To shut R up while it is importing libraries to do not ruin out
| # doctests
| r.library = lambda libname: \
| r("suppressMessages(library(%r))" % libname)
| and it seems to do its job if library loads fine, but if it doesn't then
| it is ugly again, so following code
| # But it becomes really talkative while loading incorrect library
| pukes on me
| Error in library("glmnet_bogus") :
| there is no package called 'glmnet_bogus'
| What other approaches I could try?
suppressMessages() is the best wrapper I am aware of. But if a package uses
cat() directly (rather than packageStartupMessage() which responds to
suppressMessages()) then all you can do is
Or alter the packages -- you have the source for all. I have in the past
(locally) patched packages to suppresses the line noise on startup.
Registration is open for the 2nd International conference R / Finance 2010
See http://www.RinFinance.com for details, and see you in Chicago in April!