Learn R Programming

switchcase (version 0.1.1)

alt: 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 (expr argument in the call of the switchCase() function) needs to fulfill.

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 code.if has been executed. See switchCase() for more details on return values.

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 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.

Value

An alternative branch that can be used in a switch-case construct (technically, a list object).

See Also

Other switchcase: switchCase()

Examples

Run this code
# NOT RUN {
alt(.(..expr > 10), .(cat("The result is larger than 10.")), "10plus")
# }

Run the code above in your browser using DataLab