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

Dirk Eddelbuettel edd at debian.org
Sat Dec 2 15:23:22 CET 2017


On 2 December 2017 at 08:38, Bill Denney wrote:
| Hi,
| 
| I got a message last night that some of the tests in the PKNCA package do not follow best practices.  ("Do not test the exact format of R messages (from R itself or from other packages): They change, and they can be translated.")  Specifically, I test to ensure that an error is generated when a class cannot be coerced into a data.frame: https://cran.r-project.org/web/checks/check_results_PKNCA.html
| 
| I want to ensure that I'm getting an error that the variable cannot be coerced into a data.frame.
| 
| What is the best practice to ensure that I'm getting a specific R error (about coercion) without testing the formatting of the error text?

To me this suggest testing the _condition_ triggering the error message, as
opposed to testing for the displayed text of the error message.

Dirk
 
| The only solution that immediately occurs to me is to wrap the coercion in a tryCatch and give my own error.  But, then were the R error translated, the users of my package would lose the benefit of translation.
| 
| Thanks,
| 
| Bill
| 
| ______________________________________________
| R-package-devel at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-package-devel

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



More information about the R-package-devel mailing list