Matchply: Match Each Object in List or Vector

Description Usage Arguments Details Value Examples

View source: R/match.R

Description

Applies Match to each individual object within the input rather than matching the entire object.

Usage

1

Arguments

x

a vector (including list) or expression object

...

conditions and expressions for matching. See Match for details.

Details

See Match for details on condition implementation. Default conditions using the period . are highly recommended to prevent error.

Matchply is a wrapper to lapply and sapply, depending on the input object, with ... converted to a match statement for easy use.

Value

vector depending on input x. By default, sapply is used with simplify = TRUE. This could return a vector, matrix, list, etc. When simplify = FALSE or a list is provided, the result will be a list.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
new_list <- list(
  hello = "World!",
  nice  = 2,
  meet  = "u"
)

Matchply(
  new_list,
  is.numeric  -> "found a number!",
  "{rld}"     -> "maybe found 'World'!",
  "u" | "z"   -> "found a letter",
  .  -> "found nothing"
)

matchr documentation built on Sept. 9, 2021, 5:07 p.m.

Related to Matchply in matchr...