If

  1. use_color = TRUE or

  2. under SPS main package use_crayonoption is TRUE

  3. In a console that supports colors

Then the message will be colorful, other wise no color.

"INFO" level spawns message, "WARNING" is warning, "ERROR" spawns stop, other levels use cat.

spsinfo, spswarn, spserror are higher level wrappers of msg. The only difference is they have SPS- prefix.

spsinfo has an additional arg verbose. This arg works similarly to all other verbose args in SPS:

  1. if not specified, it follows the project option. If SPS option verbose is set to TRUE, message will be displayed; if FALSE, mute the message.

  2. It can be be forced to TRUE and FALSE. TRUE will forcibly generate the msg, and FALSE will mute the message.

msg(
  msg,
  level = "INFO",
  .other_color = NULL,
  info_text = "INFO",
  warning_text = "WARNING",
  error_text = "ERROR",
  use_color = TRUE
)

spsinfo(msg, verbose = NULL)

spswarn(msg)

spserror(msg)

Arguments

msg

a character string of message or a vector of character strings, each item in the vector presents one line of words

level

typically, one of "INFO", "WARNING", "ERROR", not case sensitive. Other custom levels will work too.

.other_color

hex color code or named colors, when levels are not in "INFO", "WARNING", "ERROR", this value will be used

info_text

info level text prefix, use with "INFO" level

warning_text

warning level text prefix, use with "WARNING" level

error_text

error level text prefix, use with "ERROR" level

use_color

bool, default TRUE, to use color if supported?

verbose

bool, default get from sps project options, can be overwritten

Value

see description and details

Details

  1. If use_color is TRUE, output message will forcibly use color if the console has color support, ignore SPS use_crayon option.

  2. If use_color is FALSE, but you are using within SPS framework, the use_crayon option is set to TRUE, color will be used.

  3. Otherwise message will be no color.

Examples

msg("this is info")
#> [INFO] 2021-10-30 02:04:09 this is info
msg("this is warning", "warning")
#> Warning: 
[WARNING] 2021-10-30 02:04:09 this is warning
try(msg("this is error", "error"))
#> Error : 
[ERROR] 2021-10-30 02:04:09 this is error
msg("this is another level", "my level", "green")
#> [my level] 2021-10-30 02:04:09 this is another level
spsinfo("some msg, verbose false", verbose = FALSE) # will not show up
spsinfo("some msg, verbose true", verbose = TRUE)
#> [SPS-INFO] 2021-10-30 02:04:09 some msg, verbose true
spswarn("sps warning")
#> Warning: 
[SPS-WARNING] 2021-10-30 02:04:09 sps warning
try(spserror("sps error"))
#> Error : 
[SPS-ERROR] 2021-10-30 02:04:09 sps error