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 [3]: rpy2.__version__ | Out[4]: '2.0.8' | | so if I do | | import rpy2.robjects | r = rpy2.robjects.r | | r.library('glmnet') | | 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 | try: | r.library('glmnet_bogus') | except: | pass | | 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 sink("/dev/null") library(....) sink() 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. Dirk -- 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! ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list