condition: Generate a custom condition

Description Usage Arguments Details Value Examples

Description

condition creates a custom condition. The functions condition_message, condition_warning and condition_error are specialized to create conditions of type “message”, “warning” or “error”, respectively. Furthermore, the constructors for some standardized conditions are predefined (see details).

Usage

 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
assertion_message(message, call = sys.call(-1L), attach = NULL)

deprecated_message(message, call = sys.call(-1L), attach = NULL)

dimension_message(message, call = sys.call(-1L), attach = NULL)

future_message(message, call = sys.call(-1L), attach = NULL)

index_message(message, call = sys.call(-1L), attach = NULL)

io_message(message, call = sys.call(-1L), attach = NULL)

length_message(message, call = sys.call(-1L), attach = NULL)

library_message(message, call = sys.call(-1L), attach = NULL)

lookup_message(message, call = sys.call(-1L), attach = NULL)

missing_message(message, call = sys.call(-1L), attach = NULL)

name_message(message, call = sys.call(-1L), attach = NULL)

runtime_message(message, call = sys.call(-1L), attach = NULL)

type_message(message, call = sys.call(-1L), attach = NULL)

value_message(message, call = sys.call(-1L), attach = NULL)

assertion_warning(message, call = sys.call(-1L), attach = NULL)

deprecated_warning(message, call = sys.call(-1L), attach = NULL)

dimension_warning(message, call = sys.call(-1L), attach = NULL)

future_warning(message, call = sys.call(-1L), attach = NULL)

index_warning(message, call = sys.call(-1L), attach = NULL)

io_warning(message, call = sys.call(-1L), attach = NULL)

length_warning(message, call = sys.call(-1L), attach = NULL)

library_warning(message, call = sys.call(-1L), attach = NULL)

lookup_warning(message, call = sys.call(-1L), attach = NULL)

missing_warning(message, call = sys.call(-1L), attach = NULL)

name_warning(message, call = sys.call(-1L), attach = NULL)

runtime_warning(message, call = sys.call(-1L), attach = NULL)

type_warning(message, call = sys.call(-1L), attach = NULL)

value_warning(message, call = sys.call(-1L), attach = NULL)

assertion_error(message, call = sys.call(-1L), attach = NULL)

deprecated_error(message, call = sys.call(-1L), attach = NULL)

dimension_error(message, call = sys.call(-1L), attach = NULL)

future_error(message, call = sys.call(-1L), attach = NULL)

index_error(message, call = sys.call(-1L), attach = NULL)

io_error(message, call = sys.call(-1L), attach = NULL)

length_error(message, call = sys.call(-1L), attach = NULL)

library_error(message, call = sys.call(-1L), attach = NULL)

lookup_error(message, call = sys.call(-1L), attach = NULL)

missing_error(message, call = sys.call(-1L), attach = NULL)

name_error(message, call = sys.call(-1L), attach = NULL)

runtime_error(message, call = sys.call(-1L), attach = NULL)

type_error(message, call = sys.call(-1L), attach = NULL)

value_error(message, call = sys.call(-1L), attach = NULL)

condition(type, class = character(0L), message, call = sys.call(-1L))

condition_error(class, message, call = sys.call(-1L), attach = NULL)

condition_warning(class, message, call = sys.call(-1L), attach = NULL)

condition_message(class, message, call = sys.call(-1L), attach = NULL)

Arguments

message

[character(1)]
Information about the condition.

call

[call | NULL]
Call stack.

attach

[ANY]
Object to attach to the condition. Can be accessed via cond$attached in a tryCatch (see example).

type

[character(1)]
Should be one of “error”, “warning” or “message”.

class

[character]
Class for the condition. The functions condition_error, condition_warning and condition_message automatically append the respective type with an underscore (see example).

Details

The standardized conditions include:

“assertion”:

Assertion (on user input) failed.

“deprecated”:

Feature is deprecated.

“dimension”:

Wrong dimension.

“future”:

Feature is subject to change in the future.

“index”:

Subscript out of range.

“io”:

File/directory not found or accessible.

“length”:

Wrong length.

“library”:

Required package not installed.

“lookup”:

Named subelement does not exist.

“missing”:

Missing values.

“name”:

Failed lookup of a global variable.

“runtime”:

Something else which does not fit in any other category went wrong.

“type”:

Unexpected type/class.

“value”:

Inappropriate value.

Value

[condition].

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
# A simple IO error:
e = condition_error("io", "Failed to load file")
print(e)
class(e)

# To signal the condition, use message/warning/stop.
## Not run: 
message(e)
warning(e)
stop(e)

## End(Not run)

# These are equivalent (except the call):
w1 = condition("warning", "dimension_warning", "foo")
w2 = condition_warning("dimension", "foo")
w3 = tryCatch(dimension_warning("foo"), condition = function(e) e)

# Attach and retrieve additional information
f = function(x) {
  if(!is.numeric(x))
    assertion_error(" must be numeric", attach = x)
  x^2
}
f(1:10)

tryCatch(f(letters), assertion_error = function(e) {
  message("x must be numeric, but is ", typeof(e$attached))
})

mllg/conditions documentation built on May 23, 2019, 3:02 a.m.