Negate a predicate function so it selects what it previously rejected
Source:R/adverb-negate.R
negate.Rd
Negating a function changes TRUE
to FALSE
and FALSE
to TRUE
.
Arguments
- .p
A predicate function (i.e. a function that returns either
TRUE
orFALSE
) specified in one of the following ways:A named function, e.g.
is.character
.An anonymous function, e.g.
\(x) all(x < 0)
orfunction(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.
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()
#> [1] "x"
x |> keep(negate(is.numeric)) |> names()
#> [1] "y" "z"
# Same as
x |> discard(is.numeric)
#> $y
#> [1] TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE FALSE TRUE
#>
#> $z
#> [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
#> [18] "r" "s" "t" "u" "v" "w" "x" "y" "z"
#>