-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set lock_envir to TRUE by default #621
Conversation
This is a disruptive change, so let's wait until we are about to release `drake` version 7.0.0.
Codecov Report
@@ Coverage Diff @@
## master #621 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 78 78
Lines 6802 6802
=====================================
Hits 6802 6802
Continue to review full report at Codecov.
|
How it works
lock_environment <- function(envir) {
lockEnvironment(envir, bindings = FALSE)
lock_these <- ls(envir, all.names = FALSE)
skip_these <- ".Random.seed" # Probably unnecessary, but just in case we set all.names to TRUE above
lock_these <- setdiff(lock_these, skip_these)
lapply(X = lock_these, FUN = lockBinding, env = envir)
invisible()
}
The executing process locks the environment just before the target's command is executed and unlocks the environment afterwards. In addition, it blocks the lock so no other process can come along and lock/unlock it (guarantees the environment stays locked while the command is running, and it does not seem to cause a bottleneck in parallel computing). Lines 65 to 74 in e2cb272
|
Merging because the next release will be 7.0.0. |
cc @krlmlr, @pat-s, @rkrug
Work up to this point
If a user implements impure commands/functions as in #615 (comment), the act of building a target threatens to change upstream dependencies. To solve this problem, I implemented a
lock_envir
argument tomake()
anddrake_config()
. If set toTRUE
,drake
locks the user's environment and all its non-hidden bindings to prevent imported functions etc. from being modified.Also,
drake
itself no longer inserts built targets into the user's environment. Instead, it uses a separateconfig$eval <- new.env(parent = config$envir)
.This PR
I believe
make(lock_envir = TRUE)
is super important for reproducibility. However, it is a disruptive change, and existing impure projects may error out. That is why I thinkdrake
version 7.0.0 will be a great time to merge this PR to set thelock_envir
default value toTRUE
.Related GitHub issues and pull requests
Checklist
drake
's code of conduct, and I agree to follow its rules.testthat
unit tests totests/testthat
to confirm that any new features or functionality work correctly.devtools::check()