Skip to content

Example: Failing to find a global part of a list #56

Open
@HenrikBengtsson

Description

@HenrikBengtsson

From futureverse/furrr#92 (comment):


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

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
#> <environment: R_GlobalEnv>
#> 
#> attr(,"where")$list_of_funs
#> <environment: R_GlobalEnv>
#> 
#> attr(,"where")$`{`
#> <environment: base>
#> 
#> attr(,"where")$`$`
#> <environment: base>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions