Skip to content
Prev 61562 / 63424 Next

Unique ID for conditions to supress/rethrow selected conditions?

On Sun, 2023-04-16 at 13:52 +0200, I?aki Ucar wrote:

            
Yes, a typed condition system would be great.

I have two other ideas:



By reading the "R messages" and "preparing translactions" sections of the "R extensions manual"

https://cran.r-project.org/doc/manuals/r-release/R-exts.html#R-messages

I was thinking about using the "unique" R message texts (which are the msgid in the *.po files,
see e.g. https://github.com/r-devel/r-svn/blob/60a4db2171835067999e96fd2751b6b42c6a6ebc/src/library/base/po/de.po#L892)
to maintain a unique ID (not dependent on the actual translation into the current language).

A "simple" solution could be to pre- or postfix each message text with an ID, for example this code here

     else errorcall(call, _("non-numeric argument to function"));
     # https://github.com/r-devel/r-svn/blob/49597237842697595755415cf9147da26c8d1088/src/main/complex.c#L347

would become

     else errorcall(call, _("non-numeric argument to function [47]"));
or
     else errorcall(call, _("[47] non-numeric argument to function"));

Now the ID could be extracted more easily (at least for base R condition messages)...

This would even be back-portable to older R versions to make condition IDs broadly available "in the wild".



Another way to introduce an ID for each condition in base R would be ("the hard way")

1) by refactoring each and every code location with an embedded message string to use a centralized
   key/msg_text data structure to "look up" the appropriate message text and

2) use the key to enrich the condition as unique ID (e.g. as an attribute in the condition object).