Using Ctrl + Alt + T gives failures because of localized error messages

I am developing a package and I have written tests using the expect_error function from the testthat package. I am using its 'regexp' argument to check whether the correct error is thrown. My test looks like this:

test_that('weird localization issue', {
  skip_if_translated()
  expect_error(if (logical(0)) {print("yes")} else {print("no")}, "argument is of length zero")
})

If I run devtools::test() in the RStudio console, all tests pass. If I use Ctrl + Alt + T, the tests fail. The actual message is the German translation of the expected message:

test_cmsaf.add.R:482: failure: weird localization issue
`if (...) NULL` threw an error with unexpected message.
Expected match: "argument is of length zero"
Actual message: "Argument hat L�nge 0"

My questions are the following:

  1. Why do the two ways of running tests behave differently?
  2. How can I prevent RStudio from automatically translating error messages?
  3. Why does the function skip_if_translated() not work as I expect it to?
  4. Who is responsible for � being shown instead of the German Umlaut in the actual message?

This is the first part of the output of sessionInfo():

> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252

I use version 2.0.1 of testthat and RStudio version 1.1.463.

This is actually an RStudio bug:

Normally, messages should be translated according to the active locale (which appears to be German in your case) but that's not happening within RStudio, even though it happens in (child) R processes.

I don't immediately see the direct link between what I experienced and what you posted there, but thank you anyway.

This issue has some very annoying implications: As long as I test error messages, I cannot ...

  1. use covr::package_coverage() or covr::report().
  2. use Ctrl + Alt + E to check my package, even though running devtools::check() works fine.

I would have said that using commands in the RStudio Console works fine all the time and using the RStudio shortcuts does not work at all, but since covr::package_coverage() fails, this is not true.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.