-
Notifications
You must be signed in to change notification settings - Fork 3
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
findGlobals() chooses to be conservative when a variable is a global conditionally #31
Comments
Here's a miminal reproducible example that illustrates the problem and that can be used as a test case (in the future package). library("future")
plan(multisession, workers = 2L)
reset <- TRUE
x <- 1
y %<-% { if (reset) x <- 0; x + 1 }
y
## [1] 1
reset <- FALSE
x <- 1
y %<-% { if (reset) x <- 0; x + 1 }
y
## Error: object 'x' not found |
And for the record: ## Default
> globals::findGlobals({ if (reset) x <- 0; x + 1 }, method = "ordered", substitute = TRUE)
[1] "{" "if" "reset" "<-" "+"
> globals::findGlobals({ if (reset) x <- 0; x + 1 }, method = "conservative", substitute = TRUE)
[1] "{" "if" "reset" "<-" "+"
> globals::findGlobals({ if (reset) x <- 0; x + 1 }, method = "liberal", substitute = TRUE)
[1] "{" "if" "reset" "<-" "+" "x" |
Branch > globals::findGlobals({ if (reset) x <- 0; x + 1 }, method = "ordered", substitute = TRUE)
[1] "{" "if" "x" "reset" "<-" "+" However, this does not appear to work when inside a function, e.g. > globals::findGlobals(function() { if (reset) x <- 0; x + 1 }, method = "ordered", substitute = TRUE)
[1] "{" "if" "reset" "<-" "+" so more work is needed. |
Previously, I've found one example of this in the caret package, and just now another example in the phylolm package (variable |
Issue
findGlobals()
choose to be conservative when a variable is a global conditionally on a run-time variable/value:Here we probably want to pick up
y
as a global variable too.I'm acknowledging that such ambiguous expression should be avoid, but we still might want to support them, and there might be cases where it could be argued for. Maybe the following is an example:
Though it could be argued that what is really used here is:
The text was updated successfully, but these errors were encountered: