Message-ID: <25074.48350.241616.702973@rob.eddelbuettel.com>
Date: 2022-01-27T15:40:14Z
From: Dirk Eddelbuettel
Subject: [R-pkg-devel] Is using global assignment in package tests allowed?
In-Reply-To: <954B6ACA-AAF4-459A-93AB-2156963E0054@dcn.davis.ca.us>
On 27 January 2022 at 07:20, Jeff Newmiller 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.
Right on.
Yes a number of packages (of mine and other people) use a different approach
to maintain 'global state' without ... using 'global variables' (== bad).
The trick is something like `pkgenv <- new.env()` in R/zzz.R and to then also
set an option or two you need in .onLoad as eg `pkgenv[["prefence"]] <- "foo"`
which you can later test for, alter, ... at will.
All without running afould of what `R CMD check --as-cran` may hate, all the
while maintaining your logic flow.
Dirk
--
https://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org