in_set: Returns TRUE if value in set

Description Usage Arguments Value See Also Examples

View source: R/predicates.R

Description

This function returns a predicate function that will take a single value and return TRUE if the value is a member of the set of objects supplied. This doesn't actually check the membership of anything–it only returns a function that actually does the checking when called with a value. This is a convenience function meant to return a predicate function to be used in an assertr assertion.

Usage

1
in_set(..., allow.na = TRUE)

Arguments

...

objects that make up the set

allow.na

A logical indicating whether NAs (including NaNs) should be permitted (default TRUE)

Value

A function that takes one value and returns TRUE if the value is in the set defined by the arguments supplied by in_set and FALSE otherwise

See Also

%in%

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
predicate <- in_set(3,4)
predicate(4)

## is equivalent to

in_set(3,4)(3)

# the remainder of division by 2 is always 0 or 1
rem <- 10 %% 2
in_set(0,1)(rem)

## this is meant to be used as a predicate in an assert statement
assert(mtcars, in_set(3,4,5), gear)

## or in a pipeline, like this was meant for

library(magrittr)

mtcars %>%
  assert(in_set(3,4,5), gear) %>%
  assert(in_set(0,1), vs, am)

lorenzwalthert/assertr documentation built on May 20, 2019, 4:06 p.m.