I am trying to extract out all symbols inside the body of a function which were not defined in that function, but which were defined somewhere up the environment stack. I originally thought that I could do this using the return value of codetools::findGlobals
, but apparently this function doesn't do exactly what I thought since it misses variables referenced inside of a quoted expression. See the reproducible example below:
x = 2
y = 1
hidden = function() {
eval(quote({ x + y }))
}
revealed = function() {
x + y
}
codetools::findGlobals(hidden)
codetools::findGlobals(revealed)
Given this limitation of findGlobals
, is there a preferred alternative technique?