R/testMessage.R

#' @title Test if Message Produced
#' @description Tests if a given expression produces a message.
#' @param expr expression to test.
#' @return TRUE if a message is prodcued, FALSE otherwise.
#' @examples
#' msgFun <- function() message("Test Function")
#' noMsgFun <- function() return("Test Function")
#' testMessage(msgFun()) # TRUE
#' testMessage(noMsgFun()) # FALSE
#' @export
testMessage <- function(expr){
  if(inherits(tryCatch(expr, message = function(m) m), "message"))
    return(TRUE)
  else
    return(FALSE)
}
RaphaelS1/RSmisc documentation built on June 7, 2019, 8:20 p.m.