Skip to content
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

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

Open
HenrikBengtsson opened this issue Aug 5, 2020 · 0 comments
Open

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

HenrikBengtsson opened this issue Aug 5, 2020 · 0 comments

Comments

@HenrikBengtsson
Copy link
Collaborator

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>

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

No branches or pull requests

1 participant