Learn R Programming

optional (version 2.0.1)

fallthrough: Fallthrough function

Description

Permit a pattern matching to continue even if its argument is executed.

Usage

fallthrough(fun)

Arguments

fun

A result function used in make_opt()

Details

fallthrough(fun) can be applied to a result function fun inside a match_with() pattern. If there is a match, this will make the pattern matching continue through the other conditions at the end of the result function fun. match_with(variable, pattern, fallthrough(result-function), ...

Examples

Run this code
# NOT RUN {
library(magrittr)

a <- 4
match_with(a,
  . %>% if (. %% 2 == 0)., 
  fallthrough( function() "This number is even" ),
  . %>% if ( sqrt(.) == round(sqrt(.)) ).,  
  function() "This number is a perfect square"
)
## [1] "This number is even"   "This number is a perfect square"
# }

Run the code above in your browser using DataLab