Closed hsloot closed 3 years ago
Installing packages is a flaky thing, and I would run it during tests. You can also add extra functions that are only used in tests to a tests/testthat/helper.R
file.
@hsloot Is this still a problem? DO you have an example package that demonstrates the issue?
@gaborcsardi Yes, it is still a problem. In the original description, I linked a Github repository with an example. Unfortunately, the logs were deleted by now, but I created two new branches corresponding the commits that I mentioned in the original description (succeeding with the fix and failing without the fix) to re-run the actions.
The example is not perfect since I could not find the root cause of why the command is behaving differently on Windows and why it does not happen with R CMD BUILD
and R CMD CHECK
. In my understanding, the issue occurs if the package on which rcmdcheck
is run is not itself installed (which will often be the case in CI), and the package I try to install in the test setup depends on the to-be-checked package (you can think of the additional package as a support package for testing; e.g. with fuzzing functions for the parameter domains of various implemented functions). Since the to-be-checked package is built and installed by rcmdcheck
before the tests are run, this should not be an issue (it is only one for Windows with rcmdcheck
). Apparently, the temporary library, in which the to-be-checked package is installed, is not visible in calls to remotes::install_*
or install.packages
.
OK, I managed to hunt this down. It happens because callr sets R_ENVIRON
etc. in the R sub-process, and although this is not used by the check process, it is apparently used in some of its sub-processes, e.g. the processes started for the test files on Windows.
I think I can fix this.
For FWIW your workaround does not work for me, but putting this in setup.R
before the installation does:
Sys.unsetenv("R_ENVIRON")
Sys.unsetenv("R_ENVIRON_USER")
Sys.unsetenv("R_PROFILE")
Sys.unsetenv("R_PROFILE_USER")
Description
If
install.packages
orremotes::install_*
are called in the testthat setup for a package that imports the package on whichrcmdcheck
is run, the install command seems to behave differently on Windows. In particular, the temporary library of the to-be-checked package seems to be ignored. The consequence is either that this package is installed a second time (if the upgrade is possible and sources are available) or that the install fails. This error only appears if the to-be-checked package is not installed already whenrcmdcheck
is called. This does not happen ifR CMD build
andR CMD check
are run on the terminal directly.I am not entirely sure if that is a bug of
rcmdcheck
, but since it does not happen withR CMD build
andR CMD check
, it is at least unexpected behaviour.Background
I have a package for which I have bundled lots of (dependent) code only relevant for testing in a separate package. Since this code is only relevant for the package itself, I stored it in the tests/testthat directory and tried to install in the testthat setup. This broke my GH action CI check on Windows.
Example
I created an example with two commits on https://github.com/hsloot/rtestlib which both run an action with
rcmdcheck
on Windows, Linux and Mac, the last commit fixes the problem on Windows, but only by allowingremotes::install_*
to install missing dependencies.