[R-pkg-devel] Is using global assignment in package tests allowed?

James Pustejovsky jepu@to @end|ng |rom gm@||@com
Thu Jan 27 16:28:58 CET 2022


Thanks for your perspective. Re: "beyond my ken" I'm just being honest. My
operating assumption was that the unit testing code is run in its own
process and therefore that using global assignment would be okay (i.e., not
mucking with someone else's environment). But perhaps I'm being naive.

The package is on Github here: https://github.com/meghapsimatrix/wildmeta/
The tests that use global assignment are:
https://github.com/meghapsimatrix/wildmeta/blob/main/tests/testthat/test-rma-mv-methods.R
https://github.com/meghapsimatrix/wildmeta/blob/main/tests/testthat/test-missing-value-handling.R


On Thu, Jan 27, 2022 at 9:20 AM Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
wrote:

> I don't know the answer to your question, but "beyond my ken" doesn't
> sound like a very convincing reason. Mucking with any environment that
> isn't yours is asking for trouble... the behavior you depend on today may
> come into conflict with the code you are coordinating with when you least
> expect it.
>
> Is your code in a public version control repo?
>
> On January 27, 2022 6:55:49 AM PST, James Pustejovsky <jepusto using gmail.com>
> wrote:
> >Hello,
> >
> >I'm writing unit tests using testthat for a package that we want to submit
> >to CRAN. 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.
> >However, per CRAN policy: "Packages should not modify the global
> >environment (user’s workspace)."
> >
> >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?
> >Or to all code that is executed as part of checking the package (i.e.,
> code
> >that is never run can use <<-)?
> >
> >James
> >
> >       [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-package-devel using r-project.org mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> --
> Sent from my phone. Please excuse my brevity.
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list