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.
alt(condition, code.if, return.val = NULL, break.case = TRUE)
The condition that the test expression (expr
argument
in the call of the switchCase()
function) needs to fulfill.
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.
A value that is returned if the condition is met and after
the code in code.if
has been executed. See
switchCase()
for more details on return values.
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 code.if
has been
executed. Default is TRUE
, i.e. exiting the switch-case construct
after this branch. See switchCase()
for more details on
breaking out of a switch-case construct.
An alternative branch that can be used in a switch-case construct
(technically, a list
object).
Other switchcase:
switchCase()
# NOT RUN {
alt(.(..expr > 10), .(cat("The result is larger than 10.")), "10plus")
# }
Run the code above in your browser using DataLab