Skip to content

Commit

Permalink
Now globalsByName(names) asserts that the returned result has names i…
Browse files Browse the repository at this point in the history
…dentical to 'names' [#92]
  • Loading branch information
HenrikBengtsson committed Mar 5, 2024
1 parent f696904 commit 51a7476
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: globals
Version: 0.16.2-9002
Version: 0.16.2-9003
Depends:
R (>= 3.1.2)
Imports:
Expand All @@ -20,5 +20,5 @@ LazyLoad: TRUE
ByteCompile: TRUE
URL: https://globals.futureverse.org, https://github.com/HenrikBengtsson/globals
BugReports: https://github.com/HenrikBengtsson/globals/issues
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
11 changes: 8 additions & 3 deletions R/globalsByName.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
#' If the special argument does not exist, then the value is `NA`, and
#' the corresponding `where` attributes is `NULL`.
#'
#' @return A \link{Globals} object.
#' @return A \link{Globals} object with `length(names)` elements and
#' an attribute `where` with `length(names)` elements.
#' Both of sets of elements are named after `names`.
#'
#' @example incl/globalsByName.R
#'
#' @export
globalsByName <- function(names, envir = parent.frame(), mustExist = TRUE,
...) {
names <- as.character(names)

nnames <- length(names)

namesOrg <- names

debug <- getOption("globals.debug", FALSE)
if (debug) {
Expand Down Expand Up @@ -73,6 +76,7 @@ globalsByName <- function(names, envir = parent.frame(), mustExist = TRUE,
}
}
}
# stop_if_not(identical(names(globals), names))

if (length(dotdotdots) > 0L) {
for (name in c("...", dotdotdots)) {
Expand All @@ -93,7 +97,8 @@ globalsByName <- function(names, envir = parent.frame(), mustExist = TRUE,
globals[[name]] <- ddd
}
}

stop_if_not(identical(names(globals), namesOrg))

stop_if_not(
is.list(where),
length(where) == length(globals),
Expand Down
4 changes: 3 additions & 1 deletion man/globalsByName.Rd

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

0 comments on commit 51a7476

Please sign in to comment.