Skip to content

topenv of emptyenv

1 message · Tomas Kalibera

#
On 3/23/19 3:26 PM, Konrad Rudolph wrote:
The intuition here is that topenv() should be used with a reasonable 
execution environment and should return a reasonable execution 
environment (e.g. things you get from parent.frame(), etc). globalenv() 
is a reasonable default execution environment, emtyenv() is not). If you 
are using topenv() and especially if you are using it for something that 
is not an execution environment, there is a risk you are not doing the 
right thing - and this list may be a good place to ask for other 
solutions. topenv() as Martin said is not useful in normal user code. It 
is used in object systems (S3 and S4), in the byte-code compiler, 
sometimes in unit testing frameworks, etc.

As Martin already explained, reading the documentation as that 
"topenv(emptyenv())" would be documented to return "emptyenv()" is 
logically incorrect.

I agree, however, that it is not completely clear from the documentation 
what topenv() would do when given emptyenv() as either argument and we 
are working on addressing it. I've been looking into how much of the 
CRAN+BIOC tests (all packages) run into the special cases of topenv(), 
which btw required many hours of CPU time and some for analysis. The 
cases when topenv() is used with emptyenv() are very rare, but they 
exist (emptyenv() used as execution environment and S3 dispatch happens, 
dummy environment for S4 methods, etc).

Best
Tomas