Learn R Programming

globals (version 0.16.3)

globalsByName: Locates and retrieves a set of global variables by their names

Description

Locates and retrieves a set of global variables by their names

Usage

globalsByName(names, envir = parent.frame(), mustExist = TRUE, ...)

Value

A Globals object of named elements and an attribute where with named elements. Both of sets have names according to names.

Arguments

names

A character vector of global variable names.

envir

The environment from where to search for globals.

mustExist

If TRUE, an error is thrown if the object of the identified global cannot be located. Otherwise, the global is not returned.

...

Not used.

Special "argument" globals

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.

Examples

Run this code
f <- function(x = 42, ...) {
  globalsByName("x")
}

globals <- f()
str(globals)

globals <- f(3.14)
str(globals)


g <- function(x = 42, ...) {
  globalsByName("...")
}

globals <- g()
str(globals)

globals <- g(3.14)
str(globals)

globals <- g(3.14, 1L, b = 2L, c = 3L)
str(globals)


h <- function(x = 42, ...) {
  globalsByName("..2")
}

globals <- h(x = 3.14, a = 1, b = 2)
str(globals)

globals <- g(3.14)
str(globals)

globals <- g(3.14, 1L, b = 2L, c = 3L)
str(globals)

Run the code above in your browser using DataLab