[R-pkg-devel] Is using global assignment in package tests allowed?
Ivan Krylov
kry|ov@r00t @end|ng |rom gm@||@com
Thu Jan 27 16:26:59 CET 2022
On Thu, 27 Jan 2022 08:55:49 -0600
James Pustejovsky <jepusto using 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
More information about the R-package-devel
mailing list