When building an R package and checking it using the option --as-cran, it can happen that I receive the following warning:
For a package with a large number of tests, this can be quite annoying. The problem is that with the option --as-cran warnings are considered failures.
I was banging my head over this for a while. The internet did not offer me an answer to this problem. I understood why this happens (there are some packages that are used in the tests, but are not included in the DESCRIPTION - neither in the Imports nor in the Suggests section), but not how to quickly identify the missing packages without commenting out all the tests and commenting them in one by one until the problematic package is identified.
After having imaginary discussions with the R developers ("if you already know that something is missing, why don't you tell me what"... and more like this), I finished by reading the corresponding R code (yeah, I know, who reads the manual...) and found the solution:
so all I had to was to call:
tools:::.check_packages_used_in_tests(dir = ".", testdir = "tests/testthat")
to get my answer.
Now I had my answer, but I was also curious why I wasn't able to find this answer when searching on the internet.
I admit that the answer to this question took me almost as long as finding the solution to the original question. While working at home on the private laptop I realized I cannot reproduce the problem. Whatever I did, I always get the information about the packages actually missing:
So here is me again, having again imaginary discussions with the R developers, asking for forgiveness, this time questioning my own state of mind...
Can you guess what the difference is between the 2 scenarios? (Hint: it's not the operating system...)
I give you a few more seconds...
My epiphany: the message is incomplete if the package is checked without having an internet connection (did you guess that?).
No need to take my words for granted, here is the git repository for you to play around: github repo with a dummy example package . Just check the package while having/or not having internet connection, and compare the warnings.
The issue is now reported to the R developers: R devel bug 17978 so hopefully this will soon not be a problem anymore.
Make a promise. Show up. Do the work. Repeat.
P.S. Tested with R version 4.0.3.