futureverse / futureverse/globals
findGlobals() chooses to be conservative when a variable is a global conditionally
- Dominant language
- R
- Stars
- 29
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
# Issue
`findGlobals()` choose to be conservative when a variable is a global conditionally on a run-time variable/value:
```r
> findGlobals({ if (runif(1) < 1/2) y <- 0; y }, substitute = TRUE)
[1] "{" "if" "<" "runif" "/" "<-"
```
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:
```r
foo <- function(x, resample = FALSE) {
idxs <- slow_creation_of_indices(x) ## Make only once
future_lapply(x, FUN = function(z) {
if (resample) idxs <- sample(idxs)
z[c(1,length(z))]
})
}
```
Though it could be argued that what is really used here is:
```r
foo <- function(x, resample = FALSE) {
idxs0 <- slow_creation_of_indices(x) ## Make only once
future_lapply(x, FUN = function(z) {
if (resample) idxs <- sample(idxs0) else idxs <- idxs0
z[c(1,length(z))]
})
}
```
Contributor guide
Assessment
This issue has not been assessed yet.