R/messaging.R

Defines functions show.message show.error show.warning show.info

Documented in show.error show.info show.message show.warning

#' @title Show message helper
#'
#' @description Message output helper with option to stop execution
#' @param msg The message to be output
#' @param shouldStop Whether the message should stop execution
#' @keywords user messaging
#' @export
#' @examples
#' show.message("Message to show")
#' show.message("Error to show", TRUE)
show.message <- function(msg, shouldStop = FALSE) {
    if (shouldStop) {
        stop(paste("  - ", msg, "\n", sep=""))
    } else {
        cat(paste(msg, "\n", sep=""))
    }
}


#' @title Show Error message
#'
#' @description Error level wraper for outputing message to the user
#' @param msg The message to be output
#' @param shouldStop Whether the message should stop execution
#' @keywords user messaging
#' @export
#' @examples
#' show.error("Error to show")
#' show.error("Message to show", FALSE)
show.error <- function(msg, shouldStop = TRUE) {
    show.message(crayon::red(paste("Error:", msg)), shouldStop)
}

#' @title Show Warning message
#'
#' @description Warning level wraper for outputing message to the user
#' @param msg The message to be output
#' @param shouldStop Whether the message should stop execution
#' @keywords user messaging
#' @export
#' @examples
#' show.warning("Warning to show")
#' show.warning("Error to show", FALSE)
show.warning <- function(msg, shouldStop = FALSE) {
    show.message(crayon::yellow(paste("Warning:", msg)), shouldStop)
}

#' @title Show Info message
#'
#' @description Info level wraper for outputing message to the user
#' @param msg The message to be output
#' @param shouldStop Whether the message should stop execution
#' @keywords user messaging
#' @export
#' @examples
#' show.warning("Message to show")
#' show.warning("Info to show", FALSE)
show.info <- function(msg, shouldStop = FALSE) {
    show.message(crayon::blue(paste("Info:", msg)), shouldStop)
}
quandram/qUtils documentation built on Nov. 5, 2019, 1:58 a.m.