Skip to content

Commit

Permalink
globalsByName(): Special argument ..1, ..2, etc. do not work
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed May 19, 2023
1 parent 373961e commit 02731c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
23 changes: 12 additions & 11 deletions R/globalsByName.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,18 @@ globalsByName <- function(names, envir = parent.frame(), mustExist = TRUE,

if (length(dotdotdots) > 0L) {
for (name in dotdotdots) {
if (exists(name, envir = envir, inherits = TRUE)) {
where[[name]] <- where(name, envir = envir, inherits = TRUE)
## FIXME: If '...' in environment 'envir' specifies
## non-existing symbols, then we must not call list(...), because
## that will produce an "object not found" error.
## /HB 2023-05-19
expr <- substitute(list(arg), list(arg = as.name(name)))
ddd <- eval(expr, envir = envir, enclos = envir)
} else {
where[name] <- list(NULL)
ddd <- NA
where[name] <- list(NULL)
ddd <- NA
if (name == "...") {
if (exists("...", envir = envir, inherits = TRUE)) {
where[["..."]] <- where("...", envir = envir, inherits = TRUE)
## FIXME: If '...' in environment 'envir' specifies
## non-existing symbols, then we must not call list(...), because
## that will produce an "object not found" error.
## /HB 2023-05-19
expr <- substitute(list(arg), list(arg = as.name("...")))
ddd <- eval(expr, envir = envir, enclos = envir)
}
}
class(ddd) <- c("DotDotDotList", class(ddd))
globals[[name]] <- ddd
Expand Down
10 changes: 8 additions & 2 deletions incl/globalsByName.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ globals <- g(3.14, 1L, b = 2L, c = 3L)
str(globals)


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

globals <- h()
str(globals)

globals <- g(3.14)
str(globals)

globals <- g(3.14, 1L, b = 2L, c = 3L)
str(globals)
10 changes: 8 additions & 2 deletions man/globalsByName.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 02731c8

Please sign in to comment.