Negate a predicate function.

negate(.p, .default = FALSE)

Arguments

.p

A single predicate function, a formula describing such a predicate function, or a logical vector of the same length as .x. Alternatively, if the elements of .x are themselves lists of objects, a string indicating the name of a logical element in the inner lists. Only those elements where .p evaluates to TRUE will be modified.

.default

Optional additional argument for extractor functions (i.e. when .f is character, integer, or list). Returned when value is absent (does not exist) or empty (has length 0). .null is deprecated; please use .default instead.

Value

A new predicate function.

Examples

negate("x")
#> function (x, ...) #> { #> !(extract(x, list("x"), default = NULL)) #> } #> <environment: 0x10f8bc5f0>
# negate(is.null) # FIXME: uncomment when we switch to as_closure() negate(~ .x > 0)
#> function (..., .x = ..1, .y = ..2, . = ..1) #> { #> !(.x > 0) #> } #> <environment: 0x10948bfc0>
x <- transpose(list(x = 1:10, y = rbernoulli(10))) x %>% keep("y") %>% length()
#> [1] 5
x %>% keep(negate("y")) %>% length()
#> [1] 5
# Same as x %>% discard("y") %>% length()
#> [1] 5