handle_conditions: Handle conditions

Description Usage Arguments Details Value Examples

Description

Handle conditions

Usage

1
2
3
4
5
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

Details

Uses ConditionKeeper internally

Value

whatever the expr returns

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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])
})

conditionz documentation built on May 2, 2019, 6:19 a.m.