swh:1:snp:a4c99a50dc49f82b591f268001b320f8c3ca0041
Raw File
Tip revision: ce60f670aac0a708d3a9af5f0cf46a752d46ba8a authored by John M Chambers on 28 October 2020, 07:59:48 UTC
version 1.0-6.1
Tip revision: ce60f67
searchList.R
e1 = new.env()
assign("f", function(x)"f1", envir = e1)
e3 = new.env()
assign("g", function(x)f(x), envir = e3)
attach(e1)
attach(e3)
## Our intention is that g() calls f() in e1
g(1) #OK
## But now a new version of f() appears
e2 = new.env()
assign("f", function(x)"f2", envir = e2)
attach(e2)
search()
g(1)
## Because of search list position, the wrong function was called
## Furthermore, even having f() in the same environment as g() doesn't help:
assign("f", function(x)"f3", envir = e3)
objects(3)
detach(3)
attach(e3, pos=3)
g(1)
## And the same danger exists if the call to f() is from within the environment
assign("h", function(x)g(x), envir = e3)
detach(3)
attach(e3, pos=3)
h(1)
back to top