R Under development (unstable) (2025-04-15 r88147 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## This runs testme test script inst/testme/test-globalsOf.R > ## Don't edit - it was autogenerated by inst/testme/deploy.R > globals:::testme("globalsOf") Test 'globalsOf' ... Sourcing 9 prologue scripts ... 01/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/001.load.R' 02/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/005.globals.R' 03/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/010.record-state.R' 04/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/030.imports.R' 05/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/050.utils.R' 06/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/090.context.R' 07/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/090.options.R' 08/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/091.envvars.R' 09/09 prologue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_prologue/995.detrius-connections.R' Sourcing 9 prologue scripts ... done Running test script: 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/test-globalsOf.R' > library(globals) > message("*** globalsOf() ...") *** globalsOf() ... > message(" ** globalsOf(..., method = 'conservative'):") ** globalsOf(..., method = 'conservative'): > expr <- exprs$A > globals_c <- globalsOf(expr, method = "conservative") > str(globals_c) List of 5 $ { :.Primitive("{") $ <-:.Primitive("<-") $ c : num 3 $ d : NULL $ + :function (e1, e2) - attr(*, "where")=List of 5 ..$ { : ..$ <-: ..$ c : ..$ d : ..$ + : - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_c), c("{", "<-", + "c", "d", "+")) > globals_c <- cleanup(globals_c) > str(globals_c) List of 2 $ c: num 3 $ d: NULL - attr(*, "where")=List of 2 ..$ c: ..$ d: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_c), c("c", "d")) > where <- attr(globals_c, "where") > stopifnot(length(where) == length(globals_c), identical(where$c, + globalenv()), identical(where$d, globalenv())) > message(" ** globalsOf(..., method = 'liberal'):") ** globalsOf(..., method = 'liberal'): > expr <- exprs$A > globals_l <- globalsOf(expr, method = "liberal") > str(globals_l) List of 8 $ { :.Primitive("{") $ <-:.Primitive("<-") $ b : num 2 $ c : num 3 $ d : NULL $ + :function (e1, e2) $ a : num 0 $ e :function () - attr(*, "where")=List of 8 ..$ { : ..$ <-: ..$ b : ..$ c : ..$ d : ..$ + : ..$ a : ..$ e : - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_l), c("{", "<-", + "b", "c", "d", "+", "a", "e")) > globals_l <- cleanup(globals_l) > str(globals_l) List of 5 $ b: num 2 $ c: num 3 $ d: NULL $ a: num 0 $ e:function () - attr(*, "where")=List of 5 ..$ b: ..$ c: ..$ d: ..$ a: ..$ e: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_l), c("b", "c", + "d", "a", "e")) > where <- attr(globals_l, "where") > stopifnot(length(where) == length(globals_l), identical(where$b, + globalenv()), identical(where$c, globalenv()), identical(where$d, + glo .... [TRUNCATED] > message(" ** globalsOf(..., method = 'ordered'):") ** globalsOf(..., method = 'ordered'): > expr <- exprs$A > globals_i <- globalsOf(expr, method = "ordered") > str(globals_i) List of 8 $ { :.Primitive("{") $ <-:.Primitive("<-") $ b : num 2 $ c : num 3 $ d : NULL $ a : num 0 $ + :function (e1, e2) $ e :function () - attr(*, "where")=List of 8 ..$ { : ..$ <-: ..$ b : ..$ c : ..$ d : ..$ a : ..$ + : ..$ e : - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_i), c("{", "<-", + "b", "c", "d", "+", "a", "e")) > globals_i <- cleanup(globals_i) > str(globals_i) List of 5 $ b: num 2 $ c: num 3 $ d: NULL $ a: num 0 $ e:function () - attr(*, "where")=List of 5 ..$ b: ..$ c: ..$ d: ..$ a: ..$ e: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_i), c("b", "c", + "d", "a", "e")) > where <- attr(globals_i, "where") > stopifnot(length(where) == length(globals_i), identical(where$b, + globalenv()), identical(where$c, globalenv()), identical(where$d, + glo .... [TRUNCATED] > globals_i <- globalsOf(function(x) x <- x) > print(globals_i) $`<-` .Primitive("<-") attr(,"where") attr(,"where")$`<-` attr(,"class") [1] "Globals" "list" > globals_i <- cleanup(globals_i) > str(globals_i) Named list() - attr(*, "where")= Named list() - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_i), character(0)) > where <- attr(globals_i, "where") > stopifnot(length(where) == length(globals_i), identical(where, + setNames(list(), character(0)))) > globals_i <- globalsOf(function(x) x[1] <- 0) > print(globals_i) $`<-` .Primitive("<-") $`[` .Primitive("[") $`[<-` .Primitive("[<-") attr(,"where") attr(,"where")$`<-` attr(,"where")$`[` attr(,"where")$`[<-` attr(,"class") [1] "Globals" "list" > globals_i <- cleanup(globals_i) > str(globals_i) Named list() - attr(*, "where")= Named list() - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_i), character(0)) > where <- attr(globals_i, "where") > stopifnot(length(where) == length(globals_i), identical(where, + setNames(list(), character(0)))) > globals_i <- globalsOf(function(x) a <- x$a) > print(globals_i) $`<-` .Primitive("<-") $`$` .Primitive("$") attr(,"where") attr(,"where")$`<-` attr(,"where")$`$` attr(,"class") [1] "Globals" "list" > globals_i <- cleanup(globals_i) > str(globals_i) Named list() - attr(*, "where")= Named list() - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_i), character(0)) > where <- attr(globals_i, "where") > stopifnot(length(where) == length(globals_i), identical(where, + setNames(list(), character(0)))) > globals_i <- globalsOf(function(...) args <- list(...)) > print(globals_i) $`<-` .Primitive("<-") $list function (...) .Primitive("list") attr(,"where") attr(,"where")$`<-` attr(,"where")$list attr(,"class") [1] "Globals" "list" > globals_i <- cleanup(globals_i) > str(globals_i) Named list() - attr(*, "where")= Named list() - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_i), character(0)) > where <- attr(globals_i, "where") > stopifnot(length(where) == length(globals_i), identical(where, + setNames(list(), character(0)))) > x <- 1 > globals_i <- globalsOf({ + function(x) x + x + }, substitute = TRUE) > print(globals_i) $`{` .Primitive("{") $x [1] 1 attr(,"where") attr(,"where")$`{` attr(,"where")$x attr(,"class") [1] "Globals" "list" > globals_i <- cleanup(globals_i) > str(globals_i) List of 1 $ x: num 1 - attr(*, "where")=List of 1 ..$ x: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals_i), "x") > where <- attr(globals_i, "where") > stopifnot(length(where) == length(globals_i)) > message(" ** globalsOf() w/ globals in functions:") ** globalsOf() w/ globals in functions: > a <- 1 > bar <- function(x) x - a > foo <- function(x) bar(x) > for (method in c("ordered", "conservative", "liberal")) { + globals <- globalsOf({ + foo(3) + }, substitute = TRUE, method = method, .... [TRUNCATED] List of 1 $ foo:function (x) - attr(*, "where")=List of 1 ..$ foo: - attr(*, "class")= chr [1:2] "Globals" "list" List of 3 $ foo:function (x) $ bar:function (x) $ a : num 1 - attr(*, "where")=List of 3 ..$ foo: ..$ bar: ..$ a : - attr(*, "class")= chr [1:2] "Globals" "list" List of 3 $ foo:function (x) $ bar:function (x) $ a : num 1 - attr(*, "where")=List of 3 ..$ foo: ..$ bar: ..$ a : - attr(*, "class")= chr [1:2] "Globals" "list" List of 1 $ foo:function (x) - attr(*, "where")=List of 1 ..$ foo: - attr(*, "class")= chr [1:2] "Globals" "list" List of 3 $ foo:function (x) $ bar:function (x) $ a : num 1 - attr(*, "where")=List of 3 ..$ foo: ..$ bar: ..$ a : - attr(*, "class")= chr [1:2] "Globals" "list" List of 3 $ foo:function (x) $ bar:function (x) $ a : num 1 - attr(*, "where")=List of 3 ..$ foo: ..$ bar: ..$ a : - attr(*, "class")= chr [1:2] "Globals" "list" List of 1 $ foo:function (x) - attr(*, "where")=List of 1 ..$ foo: - attr(*, "class")= chr [1:2] "Globals" "list" List of 3 $ foo:function (x) $ bar:function (x) $ a : num 1 - attr(*, "where")=List of 3 ..$ foo: ..$ bar: ..$ a : - attr(*, "class")= chr [1:2] "Globals" "list" List of 3 $ foo:function (x) $ bar:function (x) $ a : num 1 - attr(*, "where")=List of 3 ..$ foo: ..$ bar: ..$ a : - attr(*, "class")= chr [1:2] "Globals" "list" > message(" ** globalsOf() w/ recursive functions:") ** globalsOf() w/ recursive functions: > f <- function() Recall() > globals <- globalsOf(f) > str(globals) List of 1 $ Recall:function (...) - attr(*, "where")=List of 1 ..$ Recall: - attr(*, "class")= chr [1:2] "Globals" "list" > f <- function() f() > globals <- globalsOf(f) > str(globals) List of 1 $ f:function () - attr(*, "where")=List of 1 ..$ f: - attr(*, "class")= chr [1:2] "Globals" "list" > f <- function() g() > g <- function() f() > globals_f <- globalsOf(f) > str(globals_f) List of 2 $ g:function () $ f:function () - attr(*, "where")=List of 2 ..$ g: ..$ f: - attr(*, "class")= chr [1:2] "Globals" "list" > globals_g <- globalsOf(g) > str(globals_g) List of 2 $ f:function () $ g:function () - attr(*, "where")=List of 2 ..$ f: ..$ g: - attr(*, "class")= chr [1:2] "Globals" "list" > globals_f <- globals_f[order(names(globals_f))] > globals_g <- globals_g[order(names(globals_g))] > stopifnot(identical(globals_g, globals_f)) > message("*** globalsOf() ... DONE") *** globalsOf() ... DONE > message("*** Subsetting of Globals:") *** Subsetting of Globals: > expr <- exprs$A > globals_l <- globalsOf(expr, method = "liberal") > globals_s <- globals_l[-1] > stopifnot(length(globals_s) == length(globals_l) - + 1) > stopifnot(identical(class(globals_s), class(globals_l))) > where_l <- attr(globals_l, "where") > where_s <- attr(globals_s, "where") > stopifnot(length(where_s) == length(where_l) - 1) > stopifnot(identical(where_s, where_l[-1])) > message("*** cleanup() & packagesOf():") *** cleanup() & packagesOf(): > expr <- exprs$A > globals <- globalsOf(expr, method = "conservative") > str(globals) List of 5 $ { :.Primitive("{") $ <-:.Primitive("<-") $ c : num 3 $ d : NULL $ + :function (e1, e2) - attr(*, "where")=List of 5 ..$ { : ..$ <-: ..$ c : ..$ d : ..$ + : - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("{", "<-", + "c", "d", "+")) > globals <- as.Globals(globals) > str(globals) List of 5 $ { :.Primitive("{") $ <-:.Primitive("<-") $ c : num 3 $ d : NULL $ + :function (e1, e2) - attr(*, "where")=List of 5 ..$ { : ..$ <-: ..$ c : ..$ d : ..$ + : - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("{", "<-", + "c", "d", "+")) > globals <- as.Globals(unclass(globals)) > str(globals) List of 5 $ { :.Primitive("{") $ <-:.Primitive("<-") $ c : num 3 $ d : NULL $ + :function (e1, e2) - attr(*, "where")=List of 5 ..$ { : ..$ <-: ..$ c : ..$ d : ..$ + : - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("{", "<-", + "c", "d", "+")) > pkgs <- packagesOf(globals) > print(pkgs) [1] "base" > stopifnot(length(pkgs) == 1, identical(pkgs, c("base"))) > globals <- cleanup(globals) > str(globals) List of 2 $ c: num 3 $ d: NULL - attr(*, "where")=List of 2 ..$ c: ..$ d: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("c", "d")) > pkgs <- packagesOf(globals) > print(pkgs) character(0) > stopifnot(length(pkgs) == 0) > globals <- globalsOf(quote(pi)) > stopifnot(length(globals) == 1, identical(names(globals), + "pi")) > pkgs <- packagesOf(globals) > print(pkgs) [1] "base" > stopifnot(length(pkgs) == 1, identical(pkgs, c("base"))) > message("*** globalsOf() and package functions:") *** globalsOf() and package functions: > foo <- globals::Globals > expr <- exprs$C > globals <- globalsOf(expr, recursive = FALSE) > str(globals) List of 3 $ { :.Primitive("{") $ foo :function (object = list(), ...) $ list:function (...) - attr(*, "where")=List of 3 ..$ { : ..$ foo : ..$ list: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("{", "foo", + "list")) > where <- attr(globals, "where") > stopifnot(length(where) == length(globals)) > if (!covr) stopifnot(identical(where$`{`, baseenv()), + identical(where$foo, globalenv()), identical(where$list, + baseenv())) > globals <- cleanup(globals) > str(globals) List of 1 $ foo:function (object = list(), ...) - attr(*, "where")=List of 1 ..$ foo: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("foo")) > pkgs <- packagesOf(globals) > stopifnot(pkgs == "globals") > message("*** globalsOf() and core-package functions:") *** globalsOf() and core-package functions: > sample2 <- base::sample > sum2 <- base::sum > expr <- exprs$D > globals <- globalsOf(expr, recursive = FALSE) > str(globals) List of 8 $ { :.Primitive("{") $ <- :.Primitive("<-") $ sample :function (x, size, replace = FALSE, prob = NULL) $ sum :function (..., na.rm = FALSE) $ sample2 :function (x, size, replace = FALSE, prob = NULL) $ sum2 :function (..., na.rm = FALSE) $ sessionInfo :function (package = NULL) $ isNamespaceLoaded:function (name) - attr(*, "where")=List of 8 ..$ { : ..$ <- : ..$ sample : ..$ sum : ..$ sample2 : ..$ sum2 : ..$ sessionInfo : .. ..- attr(*, "name")= chr "package:utils" .. ..- attr(*, "path")= chr "D:/RCompile/recent/R/library/utils" ..$ isNamespaceLoaded: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("{", "<-", + "sample", "sample2", "sessionInfo", "sum", "sum2", "isNamespaceLoaded")) > where <- attr(globals, "where") > stopifnot(length(where) == length(globals)) > if (!covr) stopifnot(identical(where$`<-`, baseenv()), + identical(where$sample, baseenv()), identical(where$sample2, + globalenv())) > globals <- cleanup(globals, drop = "primitives") > str(globals) List of 5 $ sample :function (x, size, replace = FALSE, prob = NULL) $ sample2 :function (x, size, replace = FALSE, prob = NULL) $ sum2 :function (..., na.rm = FALSE) $ sessionInfo :function (package = NULL) $ isNamespaceLoaded:function (name) - attr(*, "where")=List of 5 ..$ sample : ..$ sample2 : ..$ sum2 : ..$ sessionInfo : .. ..- attr(*, "name")= chr "package:utils" .. ..- attr(*, "path")= chr "D:/RCompile/recent/R/library/utils" ..$ isNamespaceLoaded: - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("sample", + "sample2", "sum2", "sessionInfo", "isNamespaceLoaded")) > globals <- cleanup(globals, drop = "internals") > str(globals) List of 4 $ sample :function (x, size, replace = FALSE, prob = NULL) $ sample2 :function (x, size, replace = FALSE, prob = NULL) $ sum2 :function (..., na.rm = FALSE) $ sessionInfo:function (package = NULL) - attr(*, "where")=List of 4 ..$ sample : ..$ sample2 : ..$ sum2 : ..$ sessionInfo: .. ..- attr(*, "name")= chr "package:utils" .. ..- attr(*, "path")= chr "D:/RCompile/recent/R/library/utils" - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("sample", + "sample2", "sum2", "sessionInfo")) > globals <- cleanup(globals) > str(globals) List of 2 $ sample2:function (x, size, replace = FALSE, prob = NULL) $ sum2 :function (..., na.rm = FALSE) - attr(*, "where")=List of 2 ..$ sample2: ..$ sum2 : - attr(*, "class")= chr [1:2] "Globals" "list" > assert_identical_sets(names(globals), c("sample2", + "sum2")) > where <- attr(globals, "where") > stopifnot(length(where) == length(globals)) > if (!covr) stopifnot(identical(where$sample2, globalenv())) > message("*** globalsOf() - exceptions ...") *** globalsOf() - exceptions ... > rm(list = "a") > res <- try({ + globals <- globalsOf({ + x <- a + }, substitute = TRUE, mustExist = TRUE) + }, silent = TRUE) > stopifnot(inherits(res, "try-error")) > message("*** globalsOf() - exceptions ... DONE") *** globalsOf() - exceptions ... DONE Sourcing 5 epilogue scripts ... 01/05 epilogue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_epilogue/002.undo-state.R' Failed to undo environment variables: - Expected environment variables: [n=207] '!ExitCode', 'ALLUSERSPROFILE', 'APPDATA', ..., 'tempdirname' - Environment variables still there: [n=0] - Environment variables missing: [n=1] 'MAKEFLAGS' Differences environment variable by environment variable: 02/05 epilogue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_epilogue/090.gc.R' 03/05 epilogue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_epilogue/099.session_info.R' 04/05 epilogue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_epilogue/995.detritus-connections.R' 05/05 epilogue script 'D:/RCompile/CRANincoming/R-devel/lib/globals/testme/_epilogue/999.detritus-files.R' Skipping, because path appears not to be an 'R CMD check' folder: 'D:/temp/2025_04_16_07_20_17_20184' Sourcing 5 epilogue scripts ... done Test time: user.self=0.4s, sys.self=0.01s, elapsed=0.5s, user.child=NAs, sys.child=NAs Test 'globalsOf' ... success > > proc.time() user system elapsed 0.65 0.15 0.73