alt: Building alterantive 'case' branches for the switch-case...

Description Usage Arguments Value See Also Examples

View source: R/switchcase.r

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

1
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

1
alt(.(..expr > 10), .(cat("The result is larger than 10.")), "10plus")

switchcase documentation built on July 1, 2020, 11:57 p.m.