I was running some tests on my R package. I noticed that the order of files output by list.files
in the console and inside R CMD check
was different. I suspect that this is because of the locale dependency of the sort
function discussed here:
R CMD check fails, devtools::test() works fine
My question is as follows: how does one eliminate the locale dependency in list.files
and make it produce consistent output for both interactive sessions and R CMD check
runs?
Reproducible example
Inside the testthat
folder, create the abc
folder with the following empty files:
c-123.txt
c-456.txt
T.db
Inside the interactive session, list.files
returns:
[1] "c-123.txt" "c-456.txt" "T.db"
Yet the following test fails when run using R CMD check
because T.db
comes first:
context("ls")
test_that("correct order", {
expect_true(list.files("abc")[1] == "c-123.txt")
})
This test is passed when using devtools::test_file('tests/testthat/test-ls.R')
in the console.