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)? Duncan Murdoch
iuke-tier@ey m@iii@g oii uiow@@edu
2024-Feb-07 13:36 UTC
[Rd] [External] Get list of active calling handlers?
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. Best, luke> > Duncan Murdoch > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Luke Tierney Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tierney at uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
Apparently Analagous Threads
- [External] Feature Request: User Prompt + Message First Execution when "Managing Search Path Conflicts"
- [External] Feature Request: User Prompt + Message First Execution when "Managing Search Path Conflicts"
- S4 Reference Classes: undesired behavior when calling method '$field()'
- [External] Feature Request: User Prompt + Message First Execution when "Managing Search Path Conflicts"
- calling handlers within R_tryEval