Repository navigation
test.data.table() creates DT in .GlobalEnv #5514
Description
Activity
- added a commit that references this issue
on Nov 8, 2022 It would be great if we could
lockEnvironment(.GlovalEnv), but for some strange reason R apparently doesn't offer any way tounlockEnvironment()afterwards. There are apparently some ways to hack together anunlockEnvironment()in C, see e.g. here, but I'd rather not do that.Good idea. Agree that's strange
unlockEnvironment()doesn't exist.
Then how aboutsave.image()before and after and binary compare. That could be a concern in a user's environment perhaps if they had large or sensitive data in.GlobalEnvand they rantest.data.table(). So it could be done in CRAN_Release.cmd and/or GLCI.- added a commit that references this issue
on Nov 9, 2022 Using 1.14.4 I checked that those commands added to CRAN_Release would have found this
DTbeing written, and that there are no others. No others in dev as of now either.Agree it's probably best to handle in GLCI (with an environment variable) or in CRAN_release, because it's fine to
lockEnvironment(.GlobalEnv)as long as the session exits after running the test.Good point. In that case it would need to be
lockEnvironment(.GlobalEnv, bindings=TRUE)otherwise it appears from reading?lockEnvironmentthat existing variables could still be changed with the defaultbindings=FALSE.I wonder if
lockEnvironment(.GlobalEnv, bindings=TRUE)would prevent.Lastand.Random.seedfrom being created/changed. Those aren't assigned by us but by base R. Those were picked up by thediffmethod so I excluded them in e956716.Maybe
lockEnvironment(.GlobalEnv, bindings=TRUE); unlockBinding(".Last", .GlobalEnv); unlockBinding(".Random.seed")would work; i.e. lock all bindings other than.Lastand.Random.seed. They could be created first by dummy calls to the R functions that create them, or setting them to NULL might be enough just to ensure the bindings exist before locking the environment after which new bindings can't be created.otherwise it appears... existing variables could still be changed...
Oh, good catch, yes, I assumed
bindings=TRUEwas the default.They could be created first by dummy calls to the R functions that create them, or setting them to NULL
Either way, should be easy enough to play. The latter looks cleaner but the risk is if some R code assume's they're non-
NULLorlength()>0.- added a commit that references this issue
on Jan 25, 2024 - added a commit that references this issue
on May 11, 2026 - added a commit that references this issue
on May 14, 2026
It shouldn't be touching
.GlobalEnvTests are already run in their own environment to isolate from .GobalEnv. That works well. But test 2036 uses
source()which needs alocal=TRUEadding.