Description Usage Arguments Details Value Examples
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).
message |
[ |
call |
[ |
attach |
[ANY] |
type |
[ |
class |
[ |
The standardized conditions include:
Assertion (on user input) failed.
Feature is deprecated.
Wrong dimension.
Feature is subject to change in the future.
Subscript out of range.
File/directory not found or accessible.
Wrong length.
Required package not installed.
Named subelement does not exist.
Missing values.
Failed lookup of a global variable.
Something else which does not fit in any other category went wrong.
Unexpected type/class.
Inappropriate value.
[condition
].
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))
})
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.