Description Usage Arguments Details Value See Also Examples
An altered switch
statement for stricter flow
control.
1 2 3 4 5 6 7 8 9 10 |
EXPR |
A character or numeric scalar based on which a decision is made. |
... |
Additional arguments from which to select an alternative. |
If EXPR
is a character scalar, the behaviour is
like the one of switch
with the exception that
unmatched values within ...
cause an error. If
EXPR
is of mode ‘numeric’, the behaviour is
like switch
but counting starts at 0 and a value
larger than the number of elements within ...
selects the last element. It is an error if EXPR
is negative or if ...
contains no arguments at
all.
Selected value from ...
.
base::switch
Other coding-functions: L
,
LL
, assert
,
check
, collect
,
contains
, flatten
,
listing
, map_names
,
map_values
, must
,
set
, sql
,
unnest
1 2 3 4 5 6 7 8 9 10 11 | # 'numeric' method
(x <- case(0, "a", "b", "c"))
stopifnot(identical(x, "a"))
(x <- case(99, "a", "b", "c"))
stopifnot(identical(x, "c"))
# 'character' method
(x <- case("b", a = "x", b = "y", c = "z"))
stopifnot(identical(x, "y"))
(x <- try(case("d", a = "x", b = "y", c = "z"), silent = TRUE))
stopifnot(inherits(x, "try-error"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.