From ripley at stats.ox.ac.uk  Fri Oct 26 14:20:18 2012
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 26 Oct 2012 13:20:18 +0100
Subject: [Rd] suppress *specific* warnings?
In-Reply-To: <5809ACD3-8FE3-4F57-AD7C-604DF82D8981@gmail.com>
References: <50844CC3.6020302@ufl.edu> <50849C77.6050106@fhcrc.org>
	<alpine.LFD.2.02.1210221153530.1869@nokomis.stat.uiowa.edu>
	<50868D80.10308@fhcrc.org>
	<20617.1591.947596.745192@stat.math.ethz.ch>
	<508919AD.3090205@gmail.com>
	<20618.21822.411471.735141@stat.math.ethz.ch>
	<5809ACD3-8FE3-4F57-AD7C-604DF82D8981@gmail.com>
Message-ID: <508A8002.3020408@stats.ox.ac.uk>

On 26/10/2012 12:04, peter dalgaard wrote:
>
> On Oct 26, 2012, at 11:17 , Martin Maechler wrote:
>
>>>>>>> Duncan Murdoch <murdoch.duncan at gmail.com>
>>>>>>>     on Thu, 25 Oct 2012 06:51:25 -0400 writes:
>>
>>> On 12-10-25 5:28 AM, Martin Maechler wrote:
>>>> Sorry guys, for coming late,
>>>> but *please* don't go there.
>>>>
>>>> I've been there years ago,
>>>> and found later why the approach is flawed "by design" :
>>>>
>>>> Internationalization / Localization:
>>>>
>>>> - If the warning comes from a "standard R" function,
>>>> the warning is almost surely different in a (say) German
>>>> locale, and your pattern won't be detected.
>>>>
>>>> - Ditto if from a recommended package.
>>>>
>>>> - If it is a warning that is not translated then it may be that
>>>> it is just not *YET*  translated.
>>
>>> I think the other Martin's suggestion addressed this:  he matched the
>>> translated message, not the English original.
>>
>>> Duncan Murdoch
>>
>> Well, I don't think I understand.
>> Of course you can only match "the message" that  warning() or
>> error()  {or rather tryCatch() ,...}  produces.
>> But you cannot guarantee nor know (for sure) if that message is 'original'
>> or translated.
>> "cannot", because AFAIK
>> we cannot guarantee  Sys.setlocale() is obeyed platform
>> independently:
>> You would have to query the current and save that, set it to C, get the
>> message, and then reset the locale to the previously saved one.
>> And these do not work reliably, on some platforms, AFAIK and
>> read our documentation.
>
> I think the point was to use gettext() on the pattern-to-match. If
> the  warning is translated, so would this be. The main limitations would seem
to be that you have to be d*mn sure to get the spelling right and,
presumably, it only works with straight string translations, not variant
forms like
>
>       msgid "found %d fatal error"
>       msgid_plural "found %d fatal errors"
>       msgstr[0] "s'ha trobat %d error fatal"
>       msgstr[1] "s'han trobat %d errors fatals"

Yes: you also need to get the domain right (and it would be unsafe not 
to specify it on the gettext() call).  And C-level messages do move 
between domains; for example between R 2.15.x and R-devel most of the 
graphics ones have moved from 'R' to 'graphics'.


-- 
Brian D. Ripley,                  ripley at 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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] suppress *specific* warnings?
Prof Brian Ripley