alt {switchcase} | R Documentation |
Building alterantive 'case' branches for the switch-case construct
Description
The alt()
function is used to build alternative 'case'
branches for the switch-case construct. Each alternative branch consist of
four elements: The test condition, the code that is executed if the
condition evaluates to TRUE
, an optional return value which
switchCase()
will return if the condition is met and after
the branch code has ben executed, and an optional logical value indicating
if the switch-case construct will be left after this branch has been
executed.
Usage
alt(condition, code.if, return.val = NULL, break.case = TRUE)
Arguments
condition |
The condition that the test expression ( |
code.if |
The code that is executed if the condition is met. If the code stretches over multiple R statements then use curly brackets to enclose the whole code segment. |
return.val |
A value that is returned if the condition is met and after
the code in |
break.case |
A logical value indicating if the switch-case construct
will be left after the condition of this alternative 'case' branch of the
switch-case construct has been met and the code in |
Value
An alternative branch that can be used in a switch-case construct
(technically, a list
object).
See Also
Other switchcase:
switchCase()
Examples
alt(.(..expr > 10), .(cat("The result is larger than 10.")), "10plus")