conditionz (version 0.1.0)

handle_conditions: Handle conditions

Description

Handle conditions

Usage

handle_conditions(expr, condition = "message", times = 1)

handle_messages(expr, times = 1)

handle_warnings(expr, times = 1)

Arguments

expr

an expression

condition

(character) one of "message" or "warning"

times

(integer) max. times a condition should be thrown. default: 1

Value

whatever the expr returns

Details

Uses ConditionKeeper internally

Examples

Run this code
# NOT RUN {
foo <- function(x) {
  message("you gave: ", x)
  return(x)
}

foo('a')
capture_message(foo('a'))
handle_conditions(foo('a'))
suppressMessages(handle_conditions(foo('a')))
handle_conditions(foo('a'), "message")

bar <- function(x) {
  for (i in x) message("you gave: ", i)
  return(x)
}
bar(1:5)
handle_conditions(bar(1:5))

handle_messages(foo('a'))

hello <- function(x) {
  warning("you gave: ", x)
  return(x)
}
handle_warnings(hello('a'))

# code block
handle_warnings({
  as.numeric(letters[1:3])
  as.numeric(letters[4:6])
  as.numeric(letters[7:9])
})
# }

Run the code above in your browser using DataCamp Workspace