info_if: Display a message, and record in a log file, if a condition...

Description Usage Arguments Value Examples

View source: R/messages.R

Description

This function calls the info() function to display a message if the specified condition is true. If a message is not specified then a generic message is displayed.

Usage

1
2
3
4
5
6
7
8
info_if(
  condition,
  ...,
  level = 1,
  msg_level = getOption("msgr.level"),
  msg_types = getOption("msgr.types"),
  log_path = getOption("msgr.log_path")
)

Arguments

condition

(boolean) The condition to check.

...

(strings) message to be displayed or written to file.

level

(integer, optional) The level of the message, from 1 to 10. Default: 1.

msg_level

(integer, optional) The maximum level of messages to output. Default: set in the option "msgr.level".

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 "msgr.types".

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 "msgr.log_path".

Value

A string is return invisibly containing the message.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Use info_if() to create conditional timed messages
info_if(2 > 1, "Condition is true so this message is shown")
info_if(1 > 2, "Condition is false so this message is not shown")

# As with info() a level can be set
info_if(2 > 1, "This is a level 2 message, so not shown by default", level = 2)

# Set default level in options to determine what is shown
options(msgr.level = 2)
info_if(2 > 1, "This is a level 2 message, so is shown now", level = 2)

# Set message types in options to determine what is shown
options(msgr.types = c("WARNING", "ERROR"))
info_if(2 > 1, "This is message, so will not be shown now")

msgr documentation built on Dec. 16, 2019, 5:41 p.m.