@osp@m m@iii@g oii @itieid-im@de
2023-Apr-16 10:56 UTC
[Rd] Unique ID for conditions to supress/rethrow selected conditions?
I am the author of the *tryCatchLog* package and want to - suppress selected conditions (warnings and messages) - rethrow selected conditions (e.g a specific warning as a message or to "rename" the condition text). I could not find any reliable unique identifier for each possible condition - that (base) R throws - that 3rd-party packages can throw (out of scope here). Is there any reliable way to identify each possible condition of base R? Are there plans to implement such an identifier ("errno")? PS: Things that do not work good enough IMHO: 1. Just use the condition classes (not really unique to distiguish between each and every condition)) 2. Try to match the condition text (it depends on the active language setting in R which cannot be switched "on the fly" on each platform and wordings or translations may even change in the future)
IƱaki Ucar
2023-Apr-16 11:52 UTC
[Rd] Unique ID for conditions to supress/rethrow selected conditions?
On Sun, 16 Apr 2023 at 12:58, nospam at altfeld-im.de <nospam at altfeld-im.de> wrote:> > I am the author of the *tryCatchLog* package and want to > > - suppress selected conditions (warnings and messages) > - rethrow selected conditions (e.g a specific warning as a message or to "rename" the condition text). > > I could not find any reliable unique identifier for each possible condition > > - that (base) R throws > - that 3rd-party packages can throw (out of scope here). > > Is there any reliable way to identify each possible condition of base R?I don't think so. As stated in the manual, "?simpleError? is the class used by ?stop? and all internal error signals".> Are there plans to implement such an identifier ("errno")?I agree that something like this would be a nice addition. With the current condition system, it would be certainly easy (but quite a lot of work) to define a hierarchy of built-in conditions, and then use them consistently throughout base R. For example,> 1 + "a"Error in 1 + "a" : non-numeric argument to binary operator could be a "typeError". And catching this is already possible:> e <- errorCondition("non-numeric argument to binary operator", class="typeError") > tryCatch(stop(e), typeError=function(e) print("hello"))[1] "hello" -- I?aki ?car
Duncan Murdoch
2023-Apr-16 12:12 UTC
[Rd] Unique ID for conditions to supress/rethrow selected conditions?
As far as I know there are no reliable unique identifiers. There appears to be a general drift towards classed conditions, but so far only a small subset of conditions are generated that way (and to tell you the truth, I forget how to detect one, even though I contributed some of them to the parser. One example (I forget whether I wrote this one or not) is https://github.com/r-devel/r-svn/blob/cf233857df61549b71eb466ceab7d081424833d6/src/main/gram.y#L1328 which raises an error with class c("pipebindDisabled", "parseError", "error", "condition"). For some conditions, it might be sufficient to generate the condition and then use (part of) the generated message as the identifier. But that's not going to always be possible. Duncan Murdoch On 16/04/2023 6:56 a.m., nospam at altfeld-im.de wrote:> I am the author of the *tryCatchLog* package and want to > > - suppress selected conditions (warnings and messages) > - rethrow selected conditions (e.g a specific warning as a message or to "rename" the condition text). > > I could not find any reliable unique identifier for each possible condition > > - that (base) R throws > - that 3rd-party packages can throw (out of scope here). > > > > Is there any reliable way to identify each possible condition of base R? > > Are there plans to implement such an identifier ("errno")? > > > > PS: Things that do not work good enough IMHO: > > 1. Just use the condition classes (not really unique to distiguish between each and every condition)) > > 2. Try to match the condition text > (it depends on the active language setting in R which cannot be switched "on the fly" on each platform > and wordings or translations may even change in the future) > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Apparently Analagous Threads
- Unique ID for conditions to supress/rethrow selected conditions?
- Unique ID for conditions to supress/rethrow selected conditions?
- iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param)
- iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param)
- iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param)