Description Usage Arguments Details Value Examples
This function allows you to execute an expression and all messages, warnings
and stops are converted to info()
, warn()
and error()
respectively.
1 2 3 4 5 6 7 8 9 |
expr |
(expression) The expression to execute. |
level |
(integer, optional) The level of messages, from 1 to 10. Default: 1. |
warn_level |
(integer, optional) The level of warnings, from 1 to 10. Default: 1. |
error_level |
(integer, optional) The level of errors, 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
|
This function can also be used to change the level
of message, so if a
function raises a message with level 1, it can be downgraded to level 2+.
Similarly it can also be used to modify the msg_level
. For example, if the
current msg_level
is set to 1, and a function raises a message with level
3, the message will not be displayed. If you want it displayed for this
function but not everywhere else, you can use with_msgr()
and set the
msg_level
to 3 for that call alone.
Whatever the expression returns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ## Not run:
test_msgr <- function(x) {
if (x == "msg") message("This is a message")
if (x == "wrn") warning("This is a warning")
if (x == "err") stop("This is an error")
}
with_msgr(test_msgr("msg"))
with_msgr(test_msgr("wrn"))
with_msgr(test_msgr("err"))
with_msgr(test_msgr("msg"), level = 2)
with_msgr(test_msgr("wrn"), level = 2)
with_msgr(test_msgr("err"), level = 2)
test_lvl <- function(x) {
if (x == "msg") info("This is a message", level = 3)
if (x == "wrn") warn("This is a warning", level = 3)
if (x == "err") error("This is an error", level = 3)
}
with_msgr(test_lvl("msg"), msg_level = 3)
with_msgr(test_lvl("wrn"), msg_level = 3)
with_msgr(test_lvl("err"), msg_level = 3)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.