fallthrough: Fallthrough function

Description Usage Arguments Details Examples

View source: R/optional.R

Description

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

Usage

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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"

optional documentation built on May 1, 2019, 9:14 p.m.