Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R CMD check fails, devtools::test() works fine

Tags:

r

Sometimes R CMD check fails when all your test run fine when you run the manually (or using devtools::test()).

I ran into one of such issues as well, when I wanted to compare results from bootstrapping using the boot package. I went into a rabbit hole looking for issues caused by parallel computation (done by boot) and Random Number Generators (RNGs).

These were all not the answers.

like image 715
wligtenberg Avatar asked Mar 09 '23 20:03

wligtenberg


1 Answers

In the end, the issue was trivial. I used base::sort() to create the levels of a factor. (To ensure that they would always align, even if the data was in a different order)

The problem is, that the default sort method depends on the locale of your system. And R CMD check uses a different locale than my interactive session.

The issue resided in this: R interactively used:LC_COLLATE=en_US.UTF-8; R CMD check used: LC_COLLATE=C;

In the details of base::sort this is mentioned:

Except for method ‘"radix"’, the sort order for character vectors
will depend on the collating sequence of the locale in use: 
see ‘Comparison’.  The sort order for factors is the order of their 
levels (which is particularly appropriate for ordered factors).

I now resolved the issue by specifying the radix sort method.

Now, all works fine.

like image 88
wligtenberg Avatar answered Mar 20 '23 13:03

wligtenberg