Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore selected warnings (and other conditions?) #11

Open
aryoda opened this issue Nov 27, 2016 · 4 comments
Open

Ignore selected warnings (and other conditions?) #11

aryoda opened this issue Nov 27, 2016 · 4 comments

Comments

@aryoda
Copy link
Owner

aryoda commented Nov 27, 2016

Add the possibility to disable the logging and printing of selected warnings.

Use cases:

  • An R script produces well know warnings that shall not pollute the log file.

Implementation hints:

  • Use a global option with a vector of strings (or regular expressions?).
    This option is the default value for a new argument in tryCatchLog().
    If the warning message contains any of these strings the warning will be dismissed.

  • Alternative implementation: Add a function suppress.selected.warning()
    and use it internally. Disadvantage: Difficult to overwrite in tryCatchLog() calls.

Links:

Localisation of messages in R is documented here:
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Locales
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Localization-of-messages

The preferred language for messages is by default taken from the locale. This can be overridden first by the setting of the environment variable LANGUAGE and then by the environment variables LC_ALL, LC_MESSAGES and LANG.

To find all possible translations of an error message you can use this solution:
https://stackoverflow.com/questions/49094581/identify-actual-message-language-settings-in-r

Other posts regarding message localization:
https://stackoverflow.com/questions/12642651/in-r-how-to-get-error-messages-in-english
https://stackoverflow.com/questions/49094581/identify-actual-message-language-settings-in-r
https://stackoverflow.com/questions/19111956/suppress-error-message-in-r

See also how the gettext toolchain is working to translate text strings contained in source code:

@aryoda
Copy link
Owner Author

aryoda commented Nov 16, 2018

Currently there is no reliable way in R to recognize specific conditions:

https://stackoverflow.com/q/52935066/4468078

Next step: Ask for advice at the r-devel mailing list (current status...)

@aryoda
Copy link
Owner Author

aryoda commented Apr 13, 2020

Related to #22 (where selected conditions must be recognized, repackaged and thrown as custom conditions - this also requires a reliable way in R to recognize specific conditions)

@aryoda
Copy link
Owner Author

aryoda commented Jul 31, 2022

Related to #71: The config could be extended with another column of a keywords-whitelist (or even regexp list) per condition class row to specify which conditions shall not be logged.

Currently the config does only allow to unconditionally (!) enable and disable logging for a condition class vis "write.to.log"!

The language translation of condition messages should not be required since the executor of a script knows quite good the configured language of the execution environment. So the configuration must just be adjusted accordingly.

@aryoda aryoda changed the title Ignore selected warnings Ignore selected warnings (and other conditions?) Jul 31, 2022
@aryoda
Copy link
Owner Author

aryoda commented Jun 27, 2023

Great news:

Adding a keyword list for conditions to be ignored could work now independently of language settings by "resetting" the language of the current R session to the language of the keywords (must be done by the user or somehow configured):

  1. With Sys.setLanguage() in R (>= 4.2.0) in R it is now possible to change the language more than once in the current R session by clearing the translation string cache:
    https://bugs.r-project.org/show_bug.cgi?id=18055

  2. An alternative implementation to change the language without side effects is implemented in withr::with_language() (calling withr::local_language()).
    The implementation also contains a lot background information what must be done why to change the language
    https://github.com/r-lib/withr/blob/main/R/language.R

    This new functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant