match_cond.ref {refer}R Documentation

Check and Evaluate Match Condition

Description

ref methods for use with Match in the matchr package.

Usage

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

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"
)


[Package refer version 0.1.0 Index]