match_cond.ref: Check and Evaluate Match Condition

Description Usage Arguments Details Value Examples

View source: R/match.R

Description

ref methods for use with Match in the matchr package.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## S3 method for class 'ref'
match_cond(cond, x, do, ...)

## S3 method for class 'sref'
match_cond(cond, x, do, ...)

## S3 method for class 'slice'
match_cond(cond, x, do, ...)

## S3 method for class 'rfexpr'
match_cond(cond, x, do, ...)

Arguments

cond

match condition

x

object being matched

do

return expression associated with the condition. If cond is matched with x, then do should be evaluated and returned in a list with TRUE: list(TRUE, eval(do)).

...

arguments passed to evaluation

Details

See Match for details about the implementation of match_cond. When matching, ref conditions check whether x is a ref object. If so, then a match occurs if the condition and x point to the same object. Otherwise, the condition is dereferenced and the resulting value is checked using the appropriate match condition. Note that a slice is never matched with a ref and vice versa, though ref and sref objects may match if they point to the same object.

Value

FALSE if no match, or a list containing TRUE and the evaluated expression

Examples

1
2
3
4
5
6
7
8
9
x <- 1:10
ref_to_x <- ref(x)

matchr::Match(
  x,
  is.character -> "is a character",
  ref_to_x     -> "same as reference",   # <- MATCH
  .            -> "anything else"
)

refer documentation built on Nov. 8, 2021, 5:08 p.m.