Skip to content
Back to formatted view

Raw Message

Message-ID: <274965D6-0C8C-4B63-85FD-EC62E3951546@denney.ws>
Date: 2017-12-02T19:19:47Z
From: Bill Denney
Subject: [R-pkg-devel] Testing for a Specific R Error
In-Reply-To: <4b20d858-9b94-c3e0-a624-380a01b1a2cd@gmail.com>

> On Dec 2, 2017, at 09:43, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> 
> I don't think there's anything better than Bill's solution, though I imagine it is possible to ask for translation of the message.  For example, sqrt(-1) currently gives a warning with English message "NaNs produced".

Another idea just occurred to me.  Get the current error text as I'm expecting it from R by generating the error in a tryCatch and then test for equality to that string.  With that, changes in R (or other packages) would be automatically updated, and it would still be a precise test for the error I'm wanting to confirm in my test:

tryCatch(as.data.frame(structure(1, class="foo")), error=function(e) e$message)

Capture the output of that tryCatch and test for equality.

Then, it will be robust to language changes and to changes in R or other packages.

I'm going to implement that unless someone indicates something that I'm missing.

Thanks,

Bill

> 
> I can ask to translate that into the current session language using
> 
> gettext("NaNs produced", domain = "R")
> 
> Figuring out the right thing for "domain" is likely a little painful: it depends on which package produced the message, and how.
> 
> I don't know if CRAN tests would complain if you tested for equality between a warning message and the result of gettext():  it's still true that if the English warning changed, the test would fail.
> 
> Duncan Murdoch