Skip to content

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

@HenrikBengtsson

Description

@HenrikBengtsson

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()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions