negate: Negate a predicate function so it selects what it previously...

View source: R/adverb-negate.R

negateR Documentation

Negate a predicate function so it selects what it previously rejected

Description

Negating a function changes TRUE to FALSE and FALSE to TRUE.

Usage

negate(.p)

Arguments

.p

A predicate function (i.e. a function that returns either TRUE or FALSE) specified in one of the following ways:

  • A named function, e.g. is.character.

  • An anonymous function, e.g. ⁠\(x) all(x < 0)⁠ or function(x) all(x < 0).

  • A formula, e.g. ~ all(.x < 0). You must use .x to refer to the first argument). Only recommended if you require backward compatibility with older versions of R.

Value

A new predicate function.

Adverbs

This function is called an adverb because it modifies the effect of a function (a verb). If you'd like to include a function created an adverb in a package, be sure to read faq-adverbs-export.

See Also

Other adverbs: auto_browse(), compose(), insistently(), partial(), possibly(), quietly(), safely(), slowly()

Examples

x <- list(x = 1:10, y = rbernoulli(10), z = letters)
x |> keep(is.numeric) |> names()
x |> keep(negate(is.numeric)) |> names()
# Same as
x |> discard(is.numeric)

purrr documentation built on Aug. 10, 2023, 9:08 a.m.