R/globalsByName.R
globalsByName.Rd
Locates and retrieves a set of global variables by their names
globalsByName(names, envir = parent.frame(), mustExist = TRUE, ...)
A character vector of global variable names.
The environment from where to search for globals.
If TRUE, an error is thrown if the object of the identified global cannot be located. Otherwise, the global is not returned.
Not used.
A Globals object.
If names
specifies "..."
, "..1"
, "..2"
, ..., then they
are interpreted as arguments ...
, ..1
, ..2
, ..., respectively.
If specified, then the corresponding elements in the results are
lists of class DotDotDotList
comprising the value of the latter.
If the special argument does not exist, then the value is NA
, and
the corresponding where
attributes is NULL
.
f <- function(x = 42, ...) {
globalsByName("x")
}
globals <- f()
str(globals)
#> List of 1
#> $ x: num 42
#> - attr(*, "where")=List of 1
#> ..$ x:<environment: 0x558e4f3056e8>
#> - attr(*, "class")= chr [1:2] "Globals" "list"
globals <- f(3.14)
str(globals)
#> List of 1
#> $ x: num 3.14
#> - attr(*, "where")=List of 1
#> ..$ x:<environment: 0x558e4f54aaf8>
#> - attr(*, "class")= chr [1:2] "Globals" "list"
g <- function(x = 42, ...) {
globalsByName("...")
}
globals <- g()
str(globals)
#> List of 1
#> $ ...: list()
#> ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list"
#> - attr(*, "where")=List of 1
#> ..$ ...:<environment: 0x558e4f77e100>
#> - attr(*, "class")= chr [1:2] "Globals" "list"
globals <- g(3.14)
str(globals)
#> List of 1
#> $ ...: list()
#> ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list"
#> - attr(*, "where")=List of 1
#> ..$ ...:<environment: 0x558e4f909cb0>
#> - attr(*, "class")= chr [1:2] "Globals" "list"
globals <- g(3.14, 1L, b = 2L, c = 3L)
str(globals)
#> List of 1
#> $ ...:List of 3
#> ..$ : int 1
#> ..$ b: int 2
#> ..$ c: int 3
#> ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list"
#> - attr(*, "where")=List of 1
#> ..$ ...:<environment: 0x558e4faedc58>
#> - attr(*, "class")= chr [1:2] "Globals" "list"
h <- function(x = 42, ...) {
globalsByName("..2")
}
globals <- h()
str(globals)
#> List of 2
#> $ ...: list()
#> ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list"
#> $ ..2: 'DotDotDotList' logi NA
#> - attr(*, "where")=List of 2
#> ..$ ...:<environment: 0x558e4c697f48>
#> ..$ ..2: NULL
#> - attr(*, "class")= chr [1:2] "Globals" "list"
globals <- g(3.14)
str(globals)
#> List of 1
#> $ ...: list()
#> ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list"
#> - attr(*, "where")=List of 1
#> ..$ ...:<environment: 0x558e4bac1ce8>
#> - attr(*, "class")= chr [1:2] "Globals" "list"
globals <- g(3.14, 1L, b = 2L, c = 3L)
str(globals)
#> List of 1
#> $ ...:List of 3
#> ..$ : int 1
#> ..$ b: int 2
#> ..$ c: int 3
#> ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list"
#> - attr(*, "where")=List of 1
#> ..$ ...:<environment: 0x558e49d6a848>
#> - attr(*, "class")= chr [1:2] "Globals" "list"