futureverse / futureverse/globals
Example: Failing to find a global part of a list
- Dominant language
- R
- Stars
- 29
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
From https://github.com/DavisVaughan/furrr/issues/92#issuecomment-669491535:
---
I think this is a globals bug (but is probably hard to fix). Right here, `globalsOf()` filters down to only functions before calling itself recursively on those functions. This filters out the _list of functions_ which should be searched. Not searching the list of functions means that `rbern()` is never identified as a global
https://github.com/HenrikBengtsson/globals/blob/24f150843038dd8f078c050f26d4a18c644b43a6/R/globalsOf.R#L110-L113
[...]
@HenrikBengtsson here is a globals only reprex that shows `rbern()` not being found
```r
library(extraDistr)
library(globals)
# uses rbern() from extraDistr
inner_fun <- function() rbern(10, 0.5)
# A function that calls another which is passed to it in a list
wrapper_fun <- function(fun_list) {
fun_list$sim_fun()
}
# A list of functions
list_of_funs <- list(sim_fun = inner_fun)
expr <- quote(function(i) wrapper_fun(list_of_funs))
globalsOf(expr)
#> $wrapper_fun
#> function(fun_list) {
#> fun_list$sim_fun()
#> }
#>
#> $list_of_funs
#> $list_of_funs$sim_fun
#> function() rbern(10, 0.5)
#>
#>
#> $`{`
#> .Primitive("{")
#>
#> $`$`
#> .Primitive("$")
#>
#> attr(,"class")
#> [1] "Globals" "list"
#> attr(,"where")
#> attr(,"where")$wrapper_fun
#>
#>
#> attr(,"where")$list_of_funs
#>
#>
#> attr(,"where")$`{`
#>
#>
#> attr(,"where")$`$`
#>
```
---
Contributor guide
Assessment
This issue has not been assessed yet.