Lets grab the environments "namespace:stats" and "package:stats"
ns = getNamespace( "stats" )
pkg = as.environment( "package:stats" )
Now lets get the function "sd" in both:
nsSd = get( "sd" , envir = ns , inherits = FALSE )
pkgSd = get( "sd" , envir = pkg , inherits = FALSE )
Are they the same? They are! But what does "same" mean? Reference or value equality?
identical( nsSd , pkgSd )
This implies reference equality, since the following returns FALSE:
test1 = function() {}
test2 = function() {}
identical( test1 , test2 )
But if that's true, it means that an Environment's frame can contain function pointers alongside function objects. Further complicating the issue is fact that a function can "live" in one environment, but the function can be told that its executing environment is another environment. Chambers SoDA doesn't seem to have an answer (its a dense book, maybe I missed it!)
So, I'd like a definitive answer. Which of the following are correct? Or is there a false trichotomy here?
nsSd
andpkgSd
are two different objects (albeit copies of each other), where the object inpkgSd
hasns
as its executing environmentnsSd
andpkgSd
are pointers to the same object.nsSd
is a pointer topkgSd
and as such they are treated as identical