On 16/04/2023 10:49 a.m., nos...@altfeld-im.de wrote:
On Sun, 2023-04-16 at 13:52 +0200, Iñaki Ucar wrote:

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.

Yes, a typed condition system would be great.

Why don't you contribute some patches to the sources to implement it in some particular area? You can follow the pattern that is used in the gram.y file: identify a class of messages, and what information is useful in them. Write a function or functions to generate errors or warnings with that class, and possibly a subclass. Then replace each error() and warning() call in some group of functions with a call to your function(s).

Even better, since that's a lot of work: propose it as a project to be funded by the R Foundation, or as a shorter project in some other way. There are now quite a number of ways to contribute to R, e.g. see

  https://github.com/r-devel/rdevguide

Duncan Murdoch

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).

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to