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

CLEANUP: globalsOf() should not return ..., if ... is not a global #75

Open
HenrikBengtsson opened this issue May 2, 2021 · 0 comments

Comments

@HenrikBengtsson
Copy link
Collaborator

HenrikBengtsson commented May 2, 2021

Adopted from #72: Currently globalsOf() reports on ... even when it "already knows" it's not one, e.g.

expr <- quote(fcn <- function() ~ list(...))
print(expr)
# fcn <- function() ~list(...)

names <- globals::findGlobals(expr)
print(names)
## [1] "<-"   "~"    "list" "..."

globals <- globals::globalsOf(expr)
str(globals)
## List of 4
##  $ <-  :.Primitive("<-") 
##  $ ~   :.Primitive("~") 
##  $ list:function (...)  
##  $ ... : 'DotDotDotList' logi NA
##  - attr(*, "class")= chr [1:2] "Globals" "list"
##  - attr(*, "where")=List of 4
##   ..$ <-  :<environment: base> 
##   ..$ ~   :<environment: base> 
##   ..$ list:<environment: base> 
##   ..$ ... : NULL

Note that structure(NA, class = "DotDotDotList") global object with a where attribute being NULL. This is meant to signal a potential misuse. However, I think it's time to graduate globals from this conservative approach and instead drop that ... element, i.e.

str(globals)
## List of 3
##  $ <-  :.Primitive("<-") 
##  $ ~   :.Primitive("~") 
##  $ list:function (...)  
##  - attr(*, "class")= chr [1:2] "Globals" "list"
##  - attr(*, "where")=List of 3
##   ..$ <-  :<environment: base> 
##   ..$ ~   :<environment: base> 
##   ..$ list:<environment: base> 

Comment: To do this, we also need to adjust the current package tests that assumes ... is returned.

BTW, can we fix this also for globals::findGlobals()?

@HenrikBengtsson HenrikBengtsson changed the title CLEANUP: globalsOf() should not return ... if ... is not a global CLEANUP: globalsOf() should not return ..., if ... is not a global May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant