warn {msgr} | R Documentation |
Display a warning, and record it in a log file.
Description
warn()
is similar to warning()
, but it also writes the warning to a log file.
Whether it is shown, or written to the log, depends on the level and type of the warning.
See details below for more information.
Usage
warn(
...,
level = 1,
msg_level = getOption("msgr.level"),
msg_types = getOption("msgr.types"),
log_path = getOption("msgr.log_path")
)
Arguments
... |
(strings) warning to be displayed or written to file. |
level |
(integer, optional) The level of the warning, from 1 to 10. Default: 1. |
msg_level |
(integer, optional) The maximum level of messages to output. Default: set
in the option |
msg_types |
(character, optional) The type to write or display. Must either NULL or one
or more from "INFO", "WARNING" or "ERROR". Default: set in the option |
log_path |
(string, optional) The file path to the text log file. If set to "", then no
logs are written. Default: set in the option |
Details
Whether a warning is shown, or written to the log, depends on two options:
-
Level: This allows control over the depth of messages. Each message can be assigned a
level
and if it is below themsg_level
(set in the package optionmsgr.level
by default) the message is displayed and written to the log. -
Type: The type is refers to whether the message is "INFO", "WARNING" or "ERROR", as produced by the functions
info()
,warn()
anderror()
respectively. If the message type is in themsg_types
(set in the package optionmsgr.types
by default) the message is displayed and written to the log. This allows you to for instance, just display errors and warnings and ignore messages.
The location of the log file is set in the package option msgr.log_path
, or as an argument to
this function. messages are added with a time stamp. If the log_path
is equal to "" then no
log is produced.
Value
A string is return invisibly containing the warning
Examples
# Use warn() to create timed warnings
warn("This is a simple warning")
warn("This is a level 2 warning, so not shown by default", level = 2)
# Set default level in options to determine what is shown
options(msgr.level = 2)
warn("This is a level 2 warning, so is shown now", level = 2)
# Set message types in options to determine what is shown
options(msgr.types = "ERROR")
warn("This is warning, so will not be shown now")