[R-pkg-devel] Is using global assignment in package tests allowed?
On Thu, 27 Jan 2022 08:55:49 -0600
James Pustejovsky <jepusto at gmail.com> wrote:
Because of some aspect of how testthat works (which is beyond my ken), I have only been able to get my tests to work by using global assignment (<<-) to create some objects on which the tests are then run.
What are you trying to achieve? Perhaps there's a better way to do that. I think that you can ask testthat-specific questions at <https://community.rstudio.com/> if they turn out to be too far from base R.
Does anyone know whether this policy applies to all code within the package, including unit tests? Or does it apply just to the code and functions in /R?
I'm not a CRAN member, but I think that the spirit of the rule only covers the user-accessible code, and tests aren't typically run in the same R session where the user objects live. For the same reason, I think that it's acceptable to test internal interfaces you don't want to export by calling them by means of package:::function.
Best regards, Ivan