Matchply {matchr}R Documentation

Match Each Object in List or Vector

Description

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

Usage

Matchply(x, ...)

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

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


[Package matchr version 0.1.0 Index]