Skip to content
Prev 2147 / 12125 Next

[R-pkg-devel] Testing for a Specific R Error

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