R Under development (unstable) (2026-03-12 r89611 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 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-findGlobals.R > ## Don't edit - it was autogenerated by inst/testme/deploy.R > globals:::testme("findGlobals") Test 'findGlobals' ... 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-findGlobals.R' > library(globals) > message("*** findGlobals() ...") *** findGlobals() ... > message(" ** findGlobals(..., method = 'conservative'):") ** findGlobals(..., method = 'conservative'): > expr <- exprs$A > globals_c <- findGlobals(expr, method = "conservative") > print(globals_c) [1] "{" "<-" "c" "d" "+" > assert_identical_sets(globals_c, c("{", "<-", "c", + "d", "+")) > message(" ** findGlobals(..., method = 'liberal'):") ** findGlobals(..., method = 'liberal'): > expr <- exprs$A > globals_l <- findGlobals(expr, method = "liberal") > print(globals_l) [1] "{" "<-" "b" "c" "d" "+" "a" "e" > assert_identical_sets(globals_l, c("{", "<-", "b", + "c", "d", "+", "a", "e")) > message(" ** findGlobals(..., method = 'ordered'):") ** findGlobals(..., method = 'ordered'): > expr <- exprs$A > globals_i <- findGlobals(expr, method = "ordered") > print(globals_i) [1] "{" "<-" "b" "c" "d" "a" "+" "e" > assert_identical_sets(globals_i, c("{", "<-", "b", + "c", "d", "+", "a", "e")) > message(" ** findGlobals(..., method = 'dfs'):") ** findGlobals(..., method = 'dfs'): > expr <- exprs$A > print(expr) { x <- b b <- 1 y <- c z <- d a <- a + 1 e <- e() } > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "<-" "b" "c" "d" "a" "+" "e" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + c("x", "y", "z")) > assert_identical_sets(globals_t, c("{", "<-", "b", + "c", "d", "+", "a", "e")) > fcn <- function() { + a <- a + 1 + a + } > print(fcn) function () { a <- a + 1 a } > globals_i <- globals::findGlobals(fcn) > print(globals_i) [1] "{" "<-" "a" "+" > assert_identical_sets(globals_i, c("{", "<-", "a", + "+")) > globals_t <- findGlobals(fcn, method = "dfs") > print(globals_t) [1] "{" "<-" "a" "+" > assert_identical_sets(globals_t, c("{", "<-", "a", + "+")) > fcn <- function() { + a + a <- a + 1 + } > print(fcn) function () { a a <- a + 1 } > globals_i <- findGlobals(fcn) > print(globals_i) [1] "{" "a" "<-" "+" > assert_identical_sets(globals_i, c("{", "a", "<-", + "+")) > globals_t <- findGlobals(fcn, method = "dfs") > print(globals_t) [1] "{" "a" "<-" "+" > assert_identical_sets(globals_t, c("{", "a", "<-", + "+")) > fcn <- function(x) x <- x > print(fcn) function (x) x <- x > globals_i <- findGlobals(fcn) > print(globals_i) [1] "<-" > assert_identical_sets(globals_i, c("<-")) > globals_t <- findGlobals(fcn, method = "dfs") > print(globals_t) [1] "<-" > assert_identical_sets(globals_t, c("<-")) > fcn <- function(x) x[1] <- 0 > print(fcn) function (x) x[1] <- 0 > globals_i <- findGlobals(fcn) > print(globals_i) [1] "<-" "[" "[<-" > assert_identical_sets(globals_i, c("<-", "[", "[<-")) > globals_t <- findGlobals(fcn, method = "dfs") > print(globals_t) [1] "[<-" > assert_identical_sets(globals_t, c("[<-")) > fcn <- function(x) a <- x$a > print(fcn) function (x) a <- x$a > globals_i <- findGlobals(fcn) > print(globals_i) [1] "<-" "$" > assert_identical_sets(globals_i, c("<-", "$")) > globals_t <- findGlobals(fcn, method = "dfs") > print(globals_t) [1] "<-" "$" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "a") > assert_identical_sets(globals_t, c("<-", "$")) > fcn <- function(...) args <- list(...) > print(fcn) function (...) args <- list(...) > globals_i <- findGlobals(fcn) > print(globals_i) [1] "<-" "list" > assert_identical_sets(globals_i, c("<-", "list")) > globals_t <- findGlobals(fcn, method = "dfs") > print(globals_t) [1] "<-" "list" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "args") > assert_identical_sets(globals_t, c("<-", "list")) > fcn <- function() args <- list(...) > print(fcn) function () args <- list(...) > globals_i <- findGlobals(fcn) > print(globals_i) [1] "<-" "list" "..." > assert_identical_sets(globals_i, c("<-", "list", "...")) > globals_t <- findGlobals(fcn, method = "dfs") > print(globals_t) [1] "<-" "list" "..." > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "args") > assert_identical_sets(globals_t, c("<-", "list", "...")) > expr <- quote({ + function(x) x + x + }) > print(expr) { function(x) x x } > globals_i <- findGlobals(expr) > print(globals_i) [1] "{" "x" > assert_identical_sets(globals_i, c("{", "x")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "x" > assert_identical_sets(globals_t, c("{", "x")) > expr <- quote({ + "x" <- 1 + x + }) > globals_i <- findGlobals(expr) > print(globals_i) [1] "{" "<-" > assert_identical_sets(globals_i, c("{", "<-")) > globals_t <- findGlobals(expr, method = "dfs") > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "x") > print(globals_t) [1] "{" "<-" > assert_identical_sets(globals_t, c("{", "<-")) > x <- list() > globals <- findGlobals(x) > print(globals) character(0) > assert_identical_sets(globals, character(0)) > globals_t <- findGlobals(x, method = "dfs") > print(globals_t) character(0) > assert_identical_sets(globals_t, character(0)) > expr <- quote(list()) > attr(expr, "abc") <- quote({ + a + }) > attr(expr, "def") <- quote({ + d + }) > globals <- findGlobals(expr) > print(globals) [1] "list" "{" "a" "d" > assert_identical_sets(globals, c("list", "{", "a", + "d")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "list" "{" "a" "d" > assert_identical_sets(globals_t, c("list", "{", "a", + "d")) > globals <- findGlobals(expr, attributes = "abc") > print(globals) [1] "list" "{" "a" > assert_identical_sets(globals, c("list", "{", "a")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "list" "{" "a" "d" > assert_identical_sets(globals_t, c("list", "{", "a", + "d")) > message(" ** findGlobals(..., tweak):") ** findGlobals(..., tweak): > tweak_another_expression <- function(expr) { + quote({ + x <- B + B <- 1 + y <- C + z <- D + }) + } > expr <- exprs$A > print(expr) { x <- b b <- 1 y <- c z <- d a <- a + 1 e <- e() } > globals_i <- findGlobals(expr, tweak = tweak_another_expression) > assert_identical_sets(globals_i, c("{", "<-", "B", + "C", "D")) > globals_t <- findGlobals(expr, tweak = tweak_another_expression, + method = "dfs") > print(globals_t) [1] "{" "<-" "B" "C" "D" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + c("x", "y", "z")) > assert_identical_sets(globals_t, c("{", "<-", "B", + "C", "D")) > message(" ** findGlobals(..., trace = TRUE):") ** findGlobals(..., trace = TRUE): > expr <- exprs$A > print(expr) { x <- b b <- 1 y <- c z <- d a <- a + 1 e <- e() } > globals_i <- findGlobals(expr, trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = { length(expr) = 7 find_globals_ordered() ... type = call Convert to an anonymous function: function () x <- b enter_global(type='function', v='<-') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: after: name class 1 <- global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='x') ... before: name class 1 <- global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () b enter_global(type='variable', v='b') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable 'b' => Nothing else to explore after: name class 1 b global enter_global(type='variable', v='b') ... done variables (with duplicates): name class 1 b global variables (no duplicates): name class 1 b global find_globals_ordered() ... done globals: [n=1] 'b' call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=1] 'b' hardcoded locals: [n=0] Add 'local' variable 'x' after: name class 1 <- global 2 x local enter_local(type='<-', v='x') ... done enter_global(type='variable', v='b') ... before: name class 1 <- global 2 x local hardcoded locals: [n=0] Add 'global' variable 'b' => Nothing else to explore after: name class 1 <- global 2 x local 3 b global enter_global(type='variable', v='b') ... done variables (with duplicates): name class 1 <- global 2 x local 3 b global variables (no duplicates): name class 1 <- global 2 x local 3 b global find_globals_ordered() ... done Add 'global' variable '<-', 'b' Add 'local' variable 'x' find_globals_ordered() ... type = call Convert to an anonymous function: function () b <- 1 enter_global(type='function', v='<-') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: after: name class 1 <- global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='b') ... before: name class 1 <- global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () 1 variables (with duplicates): [1] name class <0 rows> (or 0-length row.names) variables (no duplicates): [1] name class <0 rows> (or 0-length row.names) find_globals_ordered() ... done globals: [n=0] call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=0] hardcoded locals: [n=0] Add 'local' variable 'b' after: name class 1 <- global 2 b local enter_local(type='<-', v='b') ... done variables (with duplicates): name class 1 <- global 2 b local variables (no duplicates): name class 1 <- global 2 b local find_globals_ordered() ... done Add 'global' variable '<-' Add 'local' variable 'b' find_globals_ordered() ... type = call Convert to an anonymous function: function () y <- c enter_global(type='function', v='<-') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: after: name class 1 <- global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='y') ... before: name class 1 <- global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () c enter_global(type='variable', v='c') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable 'c' => Nothing else to explore after: name class 1 c global enter_global(type='variable', v='c') ... done variables (with duplicates): name class 1 c global variables (no duplicates): name class 1 c global find_globals_ordered() ... done globals: [n=1] 'c' call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=1] 'c' hardcoded locals: [n=0] Add 'local' variable 'y' after: name class 1 <- global 2 y local enter_local(type='<-', v='y') ... done enter_global(type='variable', v='c') ... before: name class 1 <- global 2 y local hardcoded locals: [n=0] Add 'global' variable 'c' => Nothing else to explore after: name class 1 <- global 2 y local 3 c global enter_global(type='variable', v='c') ... done variables (with duplicates): name class 1 <- global 2 y local 3 c global variables (no duplicates): name class 1 <- global 2 y local 3 c global find_globals_ordered() ... done Add 'global' variable '<-', 'c' Add 'local' variable 'y' find_globals_ordered() ... type = call Convert to an anonymous function: function () z <- d enter_global(type='function', v='<-') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: after: name class 1 <- global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='z') ... before: name class 1 <- global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () d enter_global(type='variable', v='d') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable 'd' => Nothing else to explore after: name class 1 d global enter_global(type='variable', v='d') ... done variables (with duplicates): name class 1 d global variables (no duplicates): name class 1 d global find_globals_ordered() ... done globals: [n=1] 'd' call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=1] 'd' hardcoded locals: [n=0] Add 'local' variable 'z' after: name class 1 <- global 2 z local enter_local(type='<-', v='z') ... done enter_global(type='variable', v='d') ... before: name class 1 <- global 2 z local hardcoded locals: [n=0] Add 'global' variable 'd' => Nothing else to explore after: name class 1 <- global 2 z local 3 d global enter_global(type='variable', v='d') ... done variables (with duplicates): name class 1 <- global 2 z local 3 d global variables (no duplicates): name class 1 <- global 2 z local 3 d global find_globals_ordered() ... done Add 'global' variable '<-', 'd' Add 'local' variable 'z' find_globals_ordered() ... type = call Convert to an anonymous function: function () a <- a + 1 enter_global(type='function', v='<-') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: after: name class 1 <- global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='a') ... before: name class 1 <- global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () a + 1 enter_global(type='function', v='+') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '+' => A function, but not of interest after: name class 1 + global enter_global(type='function', v='+') ... done enter_global(type='variable', v='a') ... before: name class 1 + global hardcoded locals: [n=0] Add 'global' variable 'a' => Nothing else to explore after: name class 1 + global 2 a global enter_global(type='variable', v='a') ... done variables (with duplicates): name class 1 + global 2 a global variables (no duplicates): name class 1 + global 2 a global find_globals_ordered() ... done globals: [n=2] '+', 'a' call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=2] '+', 'a' hardcoded locals: [n=0] Add 'global' variable 'a' Add 'local' variable 'a' after: name class 1 <- global 2 a global 3 a local enter_local(type='<-', v='a') ... done enter_global(type='function', v='+') ... before: name class 1 <- global 2 a global 3 a local hardcoded locals: [n=0] Add 'global' variable '+' => A function, but not of interest after: name class 1 <- global 2 a global 3 a local 4 + global enter_global(type='function', v='+') ... done enter_global(type='variable', v='a') ... before: name class 1 <- global 2 a global 3 a local 4 + global hardcoded locals: [n=0] Add 'global' variable 'a' => Nothing else to explore after: name class 1 <- global 2 a global 3 a local 4 + global 5 a global enter_global(type='variable', v='a') ... done variables (with duplicates): name class 1 <- global 2 a global 3 a local 4 + global 5 a global variables (no duplicates): name class 1 <- global 2 a global 3 + global find_globals_ordered() ... done Add 'global' variable '<-', 'a', '+' Add 'local' variable 'a' find_globals_ordered() ... type = call Convert to an anonymous function: function () e <- e() enter_global(type='function', v='<-') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: after: name class 1 <- global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='e') ... before: name class 1 <- global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () e() enter_global(type='function', v='e') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable 'e' => A function, but not of interest after: name class 1 e global enter_global(type='function', v='e') ... done variables (with duplicates): name class 1 e global variables (no duplicates): name class 1 e global find_globals_ordered() ... done globals: [n=1] 'e' call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=1] 'e' hardcoded locals: [n=0] Add 'global' variable 'e' Add 'local' variable 'e' after: name class 1 <- global 2 e global 3 e local enter_local(type='<-', v='e') ... done enter_global(type='function', v='e') ... before: name class 1 <- global 2 e global 3 e local hardcoded locals: [n=0] Add 'global' variable 'e' => A function, but not of interest after: name class 1 <- global 2 e global 3 e local 4 e global enter_global(type='function', v='e') ... done variables (with duplicates): name class 1 <- global 2 e global 3 e local 4 e global variables (no duplicates): name class 1 <- global 2 e global find_globals_ordered() ... done Add 'global' variable '<-', 'e' Add 'local' variable 'e' variables (with duplicates): name class 1 { global 2 <- global 3 b global 4 x local 5 <- global 6 b local 7 <- global 8 c global 9 y local 10 <- global 11 d global 12 z local 13 <- global 14 a global 15 + global 16 a local 17 <- global 18 e global 19 e local variables (no duplicates): name class 1 { global 2 <- global 3 b global 4 x local 5 c global 6 y local 7 d global 8 z local 9 a global 10 + global 11 e global find_globals_ordered() ... done globals: [n=8] '{', '<-', 'b', 'c', 'd', 'a', '+', 'e' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > print(globals_i) [1] "{" "<-" "b" "c" "d" "a" "+" "e" > assert_identical_sets(globals_i, c("{", "<-", "b", + "c", "d", "+", "a", "e")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "<-" "b" "c" "d" "a" "+" "e" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + c("x", "y", "z")) > assert_identical_sets(globals_t, c("{", "<-", "b", + "c", "d", "+", "a", "e")) > message(" ** findGlobals(a <- pkg::a):") ** findGlobals(a <- pkg::a): > expr <- exprs$B > print(expr) a <- pkg::a > globals_i <- findGlobals(expr) > print(globals_i) [1] "<-" "::" > assert_identical_sets(globals_i, c("<-", "::")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "<-" "::" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "a") > assert_identical_sets(globals_t, c("<-", "::")) > message(" ** findGlobals(a[1] <- 0) etc.:") ** findGlobals(a[1] <- 0) etc.: > expr <- quote(a[1] <- 0) > print(expr) a[1] <- 0 > globals_i <- findGlobals(expr) > print(globals_i) [1] "<-" "[" "a" "[<-" > false_globals <- "[" > assert_identical_sets(setdiff(globals_i, false_globals), + c("<-", "a", "[<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "[<-" "a" > assert_identical_sets(globals_t, c("a", "[<-")) > expr <- quote({ + a[1] = 0 + }) > print(expr) { a[1] = 0 } > globals_i <- findGlobals(expr) > print(globals_i) [1] "{" "=" "[" "a" "[<-" > false_globals <- "[" > assert_identical_sets(setdiff(globals_i, false_globals), + c("{", "=", "a", "[<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "[<-" "a" > assert_identical_sets(globals_t, c("{", "a", "[<-")) > expr <- quote(a[b <- 1] <- 0) > print(expr) a[b <- 1] <- 0 > globals_i <- findGlobals(expr) > print(globals_i) [1] "<-" "[" "a" "[<-" > false_globals <- "[" > assert_identical_sets(setdiff(globals_i, false_globals), + c("<-", "a", "[<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "[<-" "a" "<-" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "b") > assert_identical_sets(globals_t, c("<-", "a", "[<-")) > expr <- quote(a[b = 1] <- 0) > print(expr) a[b = 1] <- 0 > globals_i <- findGlobals(expr) > print(globals_i) [1] "<-" "[" "a" "[<-" > false_globals <- "[" > assert_identical_sets(setdiff(globals_i, false_globals), + c("<-", "a", "[<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "[<-" "a" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "b") > assert_identical_sets(globals_t, c("a", "[<-")) > expr <- quote({ + a[b <- 1] = 0 + }) > print(expr) { a[b <- 1] = 0 } > globals_i <- findGlobals(expr) > print(globals_i) [1] "{" "=" "[" "a" "<-" "[<-" > false_globals <- "[" > assert_identical_sets(setdiff(globals_i, false_globals), + c("{", "=", "a", "<-", "[<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "[<-" "a" "<-" > if (getRversion() < "4.0.0") globals_t <- setdiff(globals_t, + "b") > assert_identical_sets(globals_t, c("{", "a", "<-", + "[<-")) > expr <- quote(a$b <- 0) > print(expr) a$b <- 0 > globals_i <- findGlobals(expr) > print(globals_i) [1] "<-" "$" "a" "$<-" > false_globals <- "$" > assert_identical_sets(setdiff(globals_i, false_globals), + c("<-", "a", "$<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "$<-" "a" > assert_identical_sets(globals_t, c("a", "$<-")) > expr <- quote({ + a$b = 0 + }) > print(expr) { a$b = 0 } > globals_i <- findGlobals(expr) > print(globals_i) [1] "{" "=" "$" "a" "$<-" > false_globals <- "$" > assert_identical_sets(setdiff(globals_i, false_globals), + c("{", "=", "a", "$<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "$<-" "a" > assert_identical_sets(setdiff(globals_t, false_globals), + c("{", "a", "$<-")) > expr <- quote(names(a) <- "A") > print(expr) names(a) <- "A" > globals_i <- findGlobals(expr) > print(globals_i) [1] "<-" "names" "a" "names<-" > assert_identical_sets(globals_i, c("<-", "a", "names", + "names<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "names<-" "a" > assert_identical_sets(globals_t, c("a", "names<-")) > expr <- quote({ + names(a) = "A" + }) > print(expr) { names(a) = "A" } > globals_i <- findGlobals(expr) > print(globals_i) [1] "{" "=" "names" "a" "names<-" > assert_identical_sets(globals_i, c("{", "=", "a", + "names", "names<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "names<-" "a" > assert_identical_sets(globals_t, c("{", "a", "names<-")) > expr <- quote(names(a)[1] <- "A") > print(expr) names(a)[1] <- "A" > globals_i <- findGlobals(expr) > print(globals_i) [1] "<-" "[" "names" "a" "[<-" "names<-" > false_globals <- c("[", "[<-") > assert_identical_sets(setdiff(globals_i, false_globals), + c("<-", "a", "names", "names<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "[<-" "names<-" "names" "a" > assert_identical_sets(globals_t, c("names<-", "a", + "[<-", "names")) > expr <- quote({ + names(a)[1] = "A" + }) > print(expr) { names(a)[1] = "A" } > globals_i <- findGlobals(expr) > print(globals_i) [1] "{" "=" "[" "names" "a" "[<-" "names<-" > false_globals <- c("[", "[<-") > assert_identical_sets(setdiff(globals_i, false_globals), + c("{", "=", "a", "names", "names<-")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "[<-" "names<-" "names" "a" > assert_identical_sets(globals_t, c("{", "names<-", + "a", "[<-", "names")) > expr <- expression(x) > print(expr) expression(x) > globals_i <- findGlobals(expr) > print(globals_i) [1] "x" > assert_identical_sets(globals_i, c("x")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "x" > assert_identical_sets(globals_t, c("x")) > expr <- expression(x + y) > print(expr) expression(x + y) > globals_i <- findGlobals(expr) > print(globals_i) [1] "+" "x" "y" > assert_identical_sets(globals_i, c("+", "x", "y")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "+" "x" "y" > assert_identical_sets(globals_t, c("+", "x", "y")) > expr <- as.call(list(function(...) GLOBAL, quote(ARG))) > print(expr) (function (...) GLOBAL)(ARG) > for (method in c("conservative", "liberal", "ordered", + "dfs")) { + message(sprintf("method=%s", sQuote(method))) + globals_i <- findG .... [TRUNCATED] method='conservative' [1] "GLOBAL" "ARG" method='liberal' [1] "GLOBAL" "ARG" method='ordered' [1] "GLOBAL" "ARG" method='dfs' [1] "GLOBAL" "ARG" > expr <- quote({ + a * b + }) > globals <- findGlobals(expr, trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = { length(expr) = 2 find_globals_ordered() ... type = call Convert to an anonymous function: function () a * b enter_global(type='function', v='*') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '*' => A function, but not of interest after: name class 1 * global enter_global(type='function', v='*') ... done enter_global(type='variable', v='a') ... before: name class 1 * global hardcoded locals: [n=0] Add 'global' variable 'a' => Nothing else to explore after: name class 1 * global 2 a global enter_global(type='variable', v='a') ... done enter_global(type='variable', v='b') ... before: name class 1 * global 2 a global hardcoded locals: [n=0] Add 'global' variable 'b' => Nothing else to explore after: name class 1 * global 2 a global 3 b global enter_global(type='variable', v='b') ... done variables (with duplicates): name class 1 * global 2 a global 3 b global variables (no duplicates): name class 1 * global 2 a global 3 b global find_globals_ordered() ... done Add 'global' variable '*', 'a', 'b' variables (with duplicates): name class 1 { global 2 * global 3 a global 4 b global variables (no duplicates): name class 1 { global 2 * global 3 a global 4 b global find_globals_ordered() ... done globals: [n=4] '{', '*', 'a', 'b' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > print(globals) [1] "{" "*" "a" "b" > assert_identical_sets(globals, c("{", "*", "a", "b")) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) [1] "{" "*" "a" "b" > assert_identical_sets(globals_t, c("{", "*", "a", + "b")) > expr <- asS3(methods::getClass("S4")@prototype, complete = FALSE) > print(expr) > globals <- findGlobals(expr, trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () variables (with duplicates): [1] name class <0 rows> (or 0-length row.names) variables (no duplicates): [1] name class <0 rows> (or 0-length row.names) find_globals_ordered() ... done globals: [n=0] call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > print(globals) character(0) > assert_identical_sets(globals, character(0)) > globals_t <- findGlobals(expr, method = "dfs") > print(globals_t) character(0) > assert_identical_sets(globals, character(0)) > message("*** findGlobals() - multiple 'method':s ...") *** findGlobals() - multiple 'method':s ... > expr <- quote({ + a + 1 + a <- 1 + }) > globals <- findGlobals(expr, method = c("ordered", + "dfs")) > print(globals) [1] "{" "+" "a" "<-" > assert_identical_sets(globals, c("{", "+", "a", "<-")) > expr <- quote({ + for (x in NULL) NULL + }) > globals <- findGlobals(expr, method = c("ordered", + "dfs")) > print(globals) [1] "{" "for" > assert_identical_sets(globals, c("{", "for")) > expr <- quote({ + for (x in NULL) x + }) > globals <- findGlobals(expr, method = c("ordered", + "dfs")) > print(globals) [1] "{" "for" > assert_identical_sets(globals, c("{", "for")) > message("*** findGlobals() - multiple 'method':s ... DONE") *** findGlobals() - multiple 'method':s ... DONE > message("*** findGlobals() - builtins for conservative/liberal ...") *** findGlobals() - builtins for conservative/liberal ... > globals_c <- findGlobals(`+`, method = "conservative") > stopifnot(identical(globals_c, character(0))) > globals_l <- findGlobals(`+`, method = "liberal") > stopifnot(identical(globals_l, character(0))) > message("*** findGlobals() - builtins for conservative/liberal ... DONE") *** findGlobals() - builtins for conservative/liberal ... DONE > message("*** findGlobals() - multi-method with unlist = FALSE ...") *** findGlobals() - multi-method with unlist = FALSE ... > res <- tryCatch(findGlobals(quote(x), method = c("ordered", + "liberal"), unlist = FALSE), error = identity) > stopifnot(inherits(res, "simpleError")) > message("*** findGlobals() - multi-method with unlist = FALSE ... DONE") *** findGlobals() - multi-method with unlist = FALSE ... DONE > message("*** findGlobals() - list input ...") *** findGlobals() - list input ... > exprs_list <- list(quote(a_li + b_li), quote(c_li * + d_li)) > globals_list <- findGlobals(exprs_list, method = "ordered") > stopifnot(all(c("a_li", "b_li", "c_li", "d_li") %in% + globals_list)) > exprs_basic <- list(1, 2, TRUE, "hello") > globals_basic <- findGlobals(exprs_basic, method = "ordered") > stopifnot(identical(globals_basic, character(0))) > exprs_dots <- list(quote(..1 + ..2), quote(x_li)) > globals_dots <- findGlobals(exprs_dots, method = "ordered") > stopifnot("x_li" %in% globals_dots) > message("*** findGlobals() - list input ... DONE") *** findGlobals() - list input ... DONE > message("*** findGlobals() - debug path ...") *** findGlobals() - debug path ... > oopts <- options(globals.debug = TRUE) > globals_d1 <- findGlobals(quote(a_dbg + b_dbg), method = "ordered") [08:09:54.335] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... [08:09:54.337] | workaround 'codetools' bug #16 [08:09:54.338] | globals found: [3] '+', 'a_dbg', 'b_dbg' [08:09:54.338] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("a_dbg" %in% globals_d1) > globals_d2 <- findGlobals(quote({ + a_dbg + 1 + a_dbg <- 1 + }), method = c("ordered", "dfs")) [08:09:54.339] findGlobals(..., dotdotdot = 'warning', method = c('ordered', 'dfs'), unlist = TRUE) ... [08:09:54.340] | findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... [08:09:54.340] | : workaround 'codetools' bug #16 [08:09:54.341] | : globals found: [4] '{', '+', 'a_dbg', '<-' [08:09:54.342] | findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done [08:09:54.342] | findGlobals(..., dotdotdot = 'warning', method = 'dfs', unlist = TRUE) ... [08:09:54.347] | : globals found: [4] '{', '+', 'a_dbg', '<-' [08:09:54.348] | findGlobals(..., dotdotdot = 'warning', method = 'dfs', unlist = TRUE) ... done [08:09:54.348] | Globals found by per method: [08:09:54.349] | 'ordered': '{', '+', 'a_dbg', '<-' [delta: ] [08:09:54.349] | 'dfs': '{', '+', 'a_dbg', '<-' [delta: ] [08:09:54.350] findGlobals(..., dotdotdot = 'warning', method = c('ordered', 'dfs'), unlist = TRUE) ... done > stopifnot(length(globals_d2) > 0) > globals_d3 <- findGlobals(list(quote(a_dbg + 1)), + method = "ordered") [08:09:54.351] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... [08:09:54.351] | expr: [08:09:54.352] | findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = FALSE) ... [08:09:54.352] | : workaround 'codetools' bug #16 [08:09:54.353] | : globals found: [2] '+', 'a_dbg' [08:09:54.353] | findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = FALSE) ... done [08:09:54.354] | globals found: [2] '+', 'a_dbg' [08:09:54.355] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("a_dbg" %in% globals_d3) > expr_attr <- quote(list()) > attr(expr_attr, "my_attr") <- quote({ + z_dbg + }) > globals_d4 <- findGlobals(expr_attr, method = "ordered") [08:09:54.356] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... [08:09:54.356] | workaround 'codetools' bug #16 [08:09:54.357] | searching attributes [08:09:54.357] | findGlobals(..., dotdotdot = 'ignore', method = 'ordered', unlist = FALSE) ... [08:09:54.358] | : workaround 'codetools' bug #16 [08:09:54.359] | : globals found: [2] '{', 'z_dbg' [08:09:54.359] | findGlobals(..., dotdotdot = 'ignore', method = 'ordered', unlist = FALSE) ... done [08:09:54.360] | globals found in attributes: [2] '{', 'z_dbg' [08:09:54.360] | globals found: [3] 'list', '{', 'z_dbg' [08:09:54.361] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("z_dbg" %in% globals_d4) > options(oopts) > message("*** findGlobals() - debug path ... DONE") *** findGlobals() - debug path ... DONE > message("*** findGlobals() - trace = TRUE with method = 'ordered' ...") *** findGlobals() - trace = TRUE with method = 'ordered' ... > globals_tr1 <- findGlobals(quote(y ~ x + z), method = "ordered", + trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () y ~ x + z enter_global(type='function', v='~') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '~' type = ~ (formula) call_find_globals_with_dotdotdot(dotdotdot = 'return') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () y enter_global(type='variable', v='y') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable 'y' => Nothing else to explore after: name class 1 y global enter_global(type='variable', v='y') ... done variables (with duplicates): name class 1 y global variables (no duplicates): name class 1 y global find_globals_ordered() ... done globals: [n=1] 'y' call_find_globals_with_dotdotdot(dotdotdot = 'return') ... done Add 'global' variables 'y' call_find_globals_with_dotdotdot(dotdotdot = 'return') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () x + z enter_global(type='function', v='+') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '+' => A function, but not of interest after: name class 1 + global enter_global(type='function', v='+') ... done enter_global(type='variable', v='x') ... before: name class 1 + global hardcoded locals: [n=0] Add 'global' variable 'x' => Nothing else to explore after: name class 1 + global 2 x global enter_global(type='variable', v='x') ... done enter_global(type='variable', v='z') ... before: name class 1 + global 2 x global hardcoded locals: [n=0] Add 'global' variable 'z' => Nothing else to explore after: name class 1 + global 2 x global 3 z global enter_global(type='variable', v='z') ... done variables (with duplicates): name class 1 + global 2 x global 3 z global variables (no duplicates): name class 1 + global 2 x global 3 z global find_globals_ordered() ... done globals: [n=3] '+', 'x', 'z' call_find_globals_with_dotdotdot(dotdotdot = 'return') ... done Add 'global' variables '+', 'x', 'z' after: name class 1 ~ global 2 y global 3 + global 4 x global 5 z global enter_global(type='function', v='~') ... done variables (with duplicates): name class 1 ~ global 2 y global 3 + global 4 x global 5 z global variables (no duplicates): name class 1 ~ global 2 y global 3 + global 4 x global 5 z global find_globals_ordered() ... done globals: [n=5] '~', 'y', '+', 'x', 'z' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot(all(c("~", "y", "x", "z") %in% globals_tr1)) > globals_tr2 <- findGlobals(`+`, method = "ordered", + trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... typeof != closure find_globals_ordered() ... done globals: [n=0] call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot(identical(globals_tr2, character(0))) > globals_tr3 <- findGlobals(expression(a + b), method = "ordered", + trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () a + b enter_global(type='function', v='+') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '+' => A function, but not of interest after: name class 1 + global enter_global(type='function', v='+') ... done enter_global(type='variable', v='a') ... before: name class 1 + global hardcoded locals: [n=0] Add 'global' variable 'a' => Nothing else to explore after: name class 1 + global 2 a global enter_global(type='variable', v='a') ... done enter_global(type='variable', v='b') ... before: name class 1 + global 2 a global hardcoded locals: [n=0] Add 'global' variable 'b' => Nothing else to explore after: name class 1 + global 2 a global 3 b global enter_global(type='variable', v='b') ... done variables (with duplicates): name class 1 + global 2 a global 3 b global variables (no duplicates): name class 1 + global 2 a global 3 b global find_globals_ordered() ... done globals: [n=3] '+', 'a', 'b' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("a" %in% globals_tr3) > expr_inline <- as.call(list(function(...) GLOBAL_TR, + quote(ARG_TR))) > globals_tr4 <- findGlobals(expr_inline, method = "ordered", + trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = a call to a function find_globals_ordered() ... type = function collect_usage_function() ... parnames: [n=1] '...' formals_clean: [n=0] locals: [n=0] Add hardcoded local variables '...' hardcoded locals: [n=1] '...' walkCode(body) ... enter_global(type='variable', v='GLOBAL_TR') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=1] '...' Add 'global' variable 'GLOBAL_TR' => Nothing else to explore after: name class 1 GLOBAL_TR global enter_global(type='variable', v='GLOBAL_TR') ... done walkCode(body) ... done collect_usage_function() ... done variables (with duplicates): name class 1 GLOBAL_TR global variables (no duplicates): name class 1 GLOBAL_TR global find_globals_ordered() ... done find_globals_ordered() ... type = call Convert to an anonymous function: function () ARG_TR() enter_global(type='function', v='ARG_TR') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable 'ARG_TR' => A function, but not of interest after: name class 1 ARG_TR global enter_global(type='function', v='ARG_TR') ... done variables (with duplicates): name class 1 ARG_TR global variables (no duplicates): name class 1 ARG_TR global find_globals_ordered() ... done variables (with duplicates): name class 1 GLOBAL_TR global 2 ARG_TR global variables (no duplicates): name class 1 GLOBAL_TR global 2 ARG_TR global find_globals_ordered() ... done globals: [n=2] 'GLOBAL_TR', 'ARG_TR' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("GLOBAL_TR" %in% globals_tr4) > globals_tr5 <- findGlobals(quote(names(a_tr)[1] <- "A"), + method = "ordered", trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () names(a_tr)[1] <- "A" enter_global(type='function', v='<-') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: find_globals_ordered() ... type = call Convert to an anonymous function: function () names(a_tr)[1] enter_global(type='function', v='[') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '[' => A function, but not of interest after: name class 1 [ global enter_global(type='function', v='[') ... done enter_global(type='function', v='names') ... before: name class 1 [ global hardcoded locals: [n=0] Add 'global' variable 'names' => A function, but not of interest after: name class 1 [ global 2 names global enter_global(type='function', v='names') ... done enter_global(type='variable', v='a_tr') ... before: name class 1 [ global 2 names global hardcoded locals: [n=0] Add 'global' variable 'a_tr' => Nothing else to explore after: name class 1 [ global 2 names global 3 a_tr global enter_global(type='variable', v='a_tr') ... done variables (with duplicates): name class 1 [ global 2 names global 3 a_tr global variables (no duplicates): name class 1 [ global 2 names global 3 a_tr global find_globals_ordered() ... done Add 'global' variables '[', 'names', 'a_tr' after: name class 1 <- global 2 [ global 3 names global 4 a_tr global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='a_tr') ... before: name class 1 <- global 2 [ global 3 names global 4 a_tr global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () "A" variables (with duplicates): [1] name class <0 rows> (or 0-length row.names) variables (no duplicates): [1] name class <0 rows> (or 0-length row.names) find_globals_ordered() ... done globals: [n=0] call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=0] hardcoded locals: [n=0] Add 'local' variable 'a_tr' after: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local enter_local(type='<-', v='a_tr') ... done enter_global(type='variable', v='a_tr') ... before: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local hardcoded locals: [n=0] Add 'global' variable 'a_tr' => Nothing else to explore after: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global enter_global(type='variable', v='a_tr') ... done enter_global(type='function', v='names') ... before: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global hardcoded locals: [n=0] Add 'global' variable 'names' => A function, but not of interest after: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global enter_global(type='function', v='names') ... done enter_global(type='function', v='[<-') ... before: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global hardcoded locals: [n=0] Add 'global' variable '[<-' => A function, but not of interest after: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global 8 [<- global enter_global(type='function', v='[<-') ... done enter_global(type='function', v='names<-') ... before: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global 8 [<- global hardcoded locals: [n=0] Add 'global' variable 'names<-' => A function, but not of interest after: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global 8 [<- global 9 names<- global enter_global(type='function', v='names<-') ... done enter_global(type='variable', v='a_tr') ... before: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global 8 [<- global 9 names<- global hardcoded locals: [n=0] Add 'global' variable 'a_tr' => Nothing else to explore after: name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global 8 [<- global 9 names<- global 10 a_tr global enter_global(type='variable', v='a_tr') ... done variables (with duplicates): name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 a_tr local 6 a_tr global 7 names global 8 [<- global 9 names<- global 10 a_tr global variables (no duplicates): name class 1 <- global 2 [ global 3 names global 4 a_tr global 5 [<- global 6 names<- global find_globals_ordered() ... done globals: [n=6] '<-', '[', 'names', 'a_tr', '[<-', 'names<-' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("a_tr" %in% globals_tr5) > globals_tr6 <- findGlobals(function() { + x_tr <- x_tr + 1 + x_tr + }, method = "ordered", trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = function collect_usage_function() ... parnames: [n=0] formals_clean: [n=0] locals: [n=0] hardcoded locals: [n=0] walkCode(body) ... enter_global(type='function', v='{') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '{' => A function, but not of interest after: name class 1 { global enter_global(type='function', v='{') ... done enter_global(type='function', v='<-') ... before: name class 1 { global hardcoded locals: [n=0] Add 'global' variable '<-' LHS <- RHS: after: name class 1 { global 2 <- global enter_global(type='function', v='<-') ... done enter_local(type='<-', v='x_tr') ... before: name class 1 { global 2 <- global hardcoded locals: [n=0] LHS <- RHS: call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () x_tr + 1 enter_global(type='function', v='+') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable '+' => A function, but not of interest after: name class 1 + global enter_global(type='function', v='+') ... done enter_global(type='variable', v='x_tr') ... before: name class 1 + global hardcoded locals: [n=0] Add 'global' variable 'x_tr' => Nothing else to explore after: name class 1 + global 2 x_tr global enter_global(type='variable', v='x_tr') ... done variables (with duplicates): name class 1 + global 2 x_tr global variables (no duplicates): name class 1 + global 2 x_tr global find_globals_ordered() ... done globals: [n=2] '+', 'x_tr' call_find_globals_with_dotdotdot(dotdotdot = 'ignore') ... done RHS globals: [n=2] '+', 'x_tr' hardcoded locals: [n=0] Add 'global' variable 'x_tr' Add 'local' variable 'x_tr' after: name class 1 { global 2 <- global 3 x_tr global 4 x_tr local enter_local(type='<-', v='x_tr') ... done enter_global(type='function', v='+') ... before: name class 1 { global 2 <- global 3 x_tr global 4 x_tr local hardcoded locals: [n=0] Add 'global' variable '+' => A function, but not of interest after: name class 1 { global 2 <- global 3 x_tr global 4 x_tr local 5 + global enter_global(type='function', v='+') ... done enter_global(type='variable', v='x_tr') ... before: name class 1 { global 2 <- global 3 x_tr global 4 x_tr local 5 + global hardcoded locals: [n=0] Add 'global' variable 'x_tr' => Nothing else to explore after: name class 1 { global 2 <- global 3 x_tr global 4 x_tr local 5 + global 6 x_tr global enter_global(type='variable', v='x_tr') ... done enter_global(type='variable', v='x_tr') ... before: name class 1 { global 2 <- global 3 x_tr global 4 x_tr local 5 + global 6 x_tr global hardcoded locals: [n=0] Add 'global' variable 'x_tr' => Nothing else to explore after: name class 1 { global 2 <- global 3 x_tr global 4 x_tr local 5 + global 6 x_tr global 7 x_tr global enter_global(type='variable', v='x_tr') ... done walkCode(body) ... done collect_usage_function() ... done variables (with duplicates): name class 1 { global 2 <- global 3 x_tr global 4 x_tr local 5 + global 6 x_tr global 7 x_tr global variables (no duplicates): name class 1 { global 2 <- global 3 x_tr global 4 + global find_globals_ordered() ... done globals: [n=4] '{', '<-', 'x_tr', '+' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("x_tr" %in% globals_tr6) > globals_tr7 <- findGlobals(quote(foo_tr(a_tr)), method = "ordered", + trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... find_globals_ordered() ... type = call Convert to an anonymous function: function () foo_tr(a_tr) enter_global(type='function', v='foo_tr') ... before: [1] name class <0 rows> (or 0-length row.names) hardcoded locals: [n=0] Add 'global' variable 'foo_tr' => A function, but not of interest after: name class 1 foo_tr global enter_global(type='function', v='foo_tr') ... done enter_global(type='variable', v='a_tr') ... before: name class 1 foo_tr global hardcoded locals: [n=0] Add 'global' variable 'a_tr' => Nothing else to explore after: name class 1 foo_tr global 2 a_tr global enter_global(type='variable', v='a_tr') ... done variables (with duplicates): name class 1 foo_tr global 2 a_tr global variables (no duplicates): name class 1 foo_tr global 2 a_tr global find_globals_ordered() ... done globals: [n=2] 'foo_tr', 'a_tr' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("foo_tr" %in% globals_tr7) > message("*** findGlobals() - trace = TRUE with method = 'ordered' ... DONE") *** findGlobals() - trace = TRUE with method = 'ordered' ... DONE > message("*** findGlobals() - trace = TRUE with conservative/liberal ...") *** findGlobals() - trace = TRUE with conservative/liberal ... > globals_trc <- findGlobals(function(x) x + a_trc, + method = "conservative", trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'conservative', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... collect_usage_function() ... parnames: [n=1] 'x' formals_clean: [n=0] locals: [n=0] Add hardcoded local variables 'x' hardcoded locals: [n=1] 'x' walkCode(body) ... walkCode(body) ... done collect_usage_function() ... done globals: [n=2] '+', 'a_trc' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'conservative', unlist = TRUE) ... done > stopifnot("a_trc" %in% globals_trc) > globals_trl <- findGlobals(function(x) x + a_trl, + method = "liberal", trace = TRUE) findGlobals(..., dotdotdot = 'warning', method = 'liberal', unlist = TRUE) ... call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... collect_usage_function() ... parnames: [n=1] 'x' formals_clean: [n=0] locals: [n=0] Add hardcoded local variables 'x' hardcoded locals: [n=1] 'x' walkCode(body) ... walkCode(body) ... done collect_usage_function() ... done globals: [n=2] '+', 'a_trl' call_find_globals_with_dotdotdot(dotdotdot = 'warning') ... done findGlobals(..., dotdotdot = 'warning', method = 'liberal', unlist = TRUE) ... done > stopifnot("a_trl" %in% globals_trl) > message("*** findGlobals() - trace = TRUE with conservative/liberal ... DONE") *** findGlobals() - trace = TRUE with conservative/liberal ... DONE > message("*** findGlobals() - tweak with multi-method ...") *** findGlobals() - tweak with multi-method ... > my_tweak <- function(expr) quote(TWEAKED_VAR + 1) > globals_tw <- findGlobals(quote(original_var), method = c("ordered", + "dfs"), tweak = my_tweak) > stopifnot("TWEAKED_VAR" %in% globals_tw) > oopts <- options(globals.debug = TRUE) > globals_tw2 <- findGlobals(quote(original_var), method = c("ordered", + "dfs"), tweak = my_tweak) [08:09:54.501] findGlobals(..., dotdotdot = 'warning', method = c('ordered', 'dfs'), unlist = TRUE) ... [08:09:54.501] | tweaking expression using function [08:09:54.503] | findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... [08:09:54.503] | : workaround 'codetools' bug #16 [08:09:54.504] | : globals found: [2] '+', 'TWEAKED_VAR' [08:09:54.504] | findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done [08:09:54.505] | findGlobals(..., dotdotdot = 'warning', method = 'dfs', unlist = TRUE) ... [08:09:54.507] | : globals found: [2] '+', 'TWEAKED_VAR' [08:09:54.508] | findGlobals(..., dotdotdot = 'warning', method = 'dfs', unlist = TRUE) ... done [08:09:54.508] | Globals found by per method: [08:09:54.509] | 'ordered': '+', 'TWEAKED_VAR' [delta: ] [08:09:54.509] | 'dfs': '+', 'TWEAKED_VAR' [delta: ] [08:09:54.510] findGlobals(..., dotdotdot = 'warning', method = c('ordered', 'dfs'), unlist = TRUE) ... done > stopifnot("TWEAKED_VAR" %in% globals_tw2) > globals_tw3 <- findGlobals(quote(original_var), method = "ordered", + tweak = my_tweak) [08:09:54.510] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... [08:09:54.511] | tweaking expression using function [08:09:54.511] | workaround 'codetools' bug #16 [08:09:54.512] | globals found: [2] '+', 'TWEAKED_VAR' [08:09:54.513] findGlobals(..., dotdotdot = 'warning', method = 'ordered', unlist = TRUE) ... done > stopifnot("TWEAKED_VAR" %in% globals_tw3) > options(oopts) > message("*** findGlobals() - tweak with multi-method ... DONE") *** findGlobals() - tweak with multi-method ... DONE > message("*** findGlobals() ... DONE") *** findGlobals() ... 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=212] '!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/2026_03_13_07_10_17_31522' Sourcing 5 epilogue scripts ... done Test time: user.self=0.6s, sys.self=0.02s, elapsed=0.6s, user.child=NAs, sys.child=NAs Test 'findGlobals' ... success > > proc.time() user system elapsed 0.73 0.09 0.76