From murdoch@dunc@n @end|ng |rom gm@||@com  Wed Feb  7 15:08:05 2024
From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch)
Date: Wed, 7 Feb 2024 09:08:05 -0500
Subject: [Rd] [External]  Get list of active calling handlers?
In-Reply-To: <164561a1-1acb-e69-cad-7a831e23b0ea@uiowa.edu>
References: <e5f12cfa-7efa-41e8-b152-6e9ef8af39b9@gmail.com>
 <164561a1-1acb-e69-cad-7a831e23b0ea@uiowa.edu>
Message-ID: <5884a0b1-7316-4444-bda0-cbf82f2eb72f@gmail.com>

On 07/02/2024 8:36 a.m., luke-tierney at uiowa.edu wrote:
> On Tue, 6 Feb 2024, Duncan Murdoch wrote:
> 
>> The SO post https://stackoverflow.com/q/77943180 tried to call
>> globalCallingHandlers() from a function, and it failed with the error message
>> "should not be called with handlers on the stack".  A much simpler
>> illustration of the same error comes from this line:
>>
>>   try(globalCallingHandlers(warning = function(e) e))
>>
>> The problem here is that try() sets an error handler, and
>> globalCallingHandlers() sees it and aborts.
>>
>> If I call globalCallingHandlers() with no arguments, I get a list of
>> currently active global handlers.  Is there also a way to get a list of
>> active handlers, including non-global ones (like the one try() added in the
>> line above)?
> 
> There is not. The internal stack is not safe to allow to escape to the
> R level.  It would be possible to write a reflection function to
> provide some information, but it would be a fair bit of work to design
> and I don't think would be of enough value to justify that.
> 
> The original SO question would be better addressed to
> Posit/RStudio. Someone with enough motivation might also be able to
> figure out an answer by looking at the source code at
> https://github.com/rstudio/rstudio.

Thanks!

Duncan



[Rd] [External] Get list of active calling handlers?
Duncan Murdoch