(This question is also asked at Github here)
After an upgrade of R to 4.0.2 tests fail because it seems, the algorithm of sort
in testthat
changed. The following shows, that base::sort()
and browser()
are fine in R 4.0.2 (See this question, why this check is added.):
y <- c("Schaffhausen", "Schwyz", "Seespital", "SRZ")
print(sort(y))
# [1] "Schaffhausen" "Schwyz" "Seespital" "SRZ"
browser()
print(sort(y))
# [1] "Schaffhausen" "Schwyz" "Seespital" "SRZ"
But if you create a package, call it testsort
, add test-environment using usethis::use_testthat()
and add a file "test-sort.R" in /testsort/tests/testthat/
test_that("test sort", {
xx <- c("Schaffhausen", "Schwyz", "Seespital", "SRZ")
print("")
# bowser()
print(sort(xx))
expect_equal(sort(xx), c("Schaffhausen", "Schwyz", "Seespital", "SRZ"))
})
you get
==> devtools::test()
Loading testsort
Testing testsort
v | OK F W S | Context
/ | 0 | sort[1] ""
[1] "SRZ" "Schaffhausen" "Schwyz" "Seespital"
v | 1 | sort
== Results =============================================================================
OK: 1
Failed: 0
Warnings: 0
Skipped: 0
I used debug(sort)
and devtools::test()
in the RStudio console(!) but was not able to figure out what happens.
R.version
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 4
minor 0.2
year 2020
month 06
day 22
svn rev 78730
language R
version.string R version 4.0.2 (2020-06-22)
nickname Taking Off Again
At present, testthat
2.3.2 is up to date, that is there is no newer version of testthat.
Thanks to @Ulugbek Umirov from test:
10.5 CRAN notes
CRAN will run your tests on all CRAN platforms: Windows, Mac, Linux and Solaris. There are a few things to bear in mind:
Note that tests are always run in the English language (LANGUAGE=EN) and with C sort order (LC_COLLATE=C). This minimises spurious differences between platforms.
test
behaviour as a bug, because everything is correct in R 4.0.2? But thanks for your comment, with my very limited knowledge about encoding, this seems to explain everything. – Veterinarywithr::local_collate("C", .local_envir = .env)
. Furthernmore, this commit caused the change. – Veterinary