Skip to contents

specify_each() creates a function that will call stabilize_each() with the provided spec, letting an element-wise spec be reused and nested inside other specify_*()/stabilize_*() calls.

Usage

specify_each(spec)

Arguments

spec

(function) A single stabilizer or coercion function, such as a to_* function (to_chr(), etc.), a stabilize_* function (stabilize_chr(), etc.), or a function produced by a specify_*() call (specify_chr(), etc.). Applied independently to each element of x.

Value

A function of class "stbl_specified_fn" that calls stabilize_each() with the provided spec. The generated function will also accept simplify and ... to pass to stabilize_each(). You can copy/paste the body of the resulting function if you want to provide additional context or functionality.

Examples

stabilize_ints <- specify_each(stabilize_int)
stabilize_ints(list("1", "2", "3"))
#> [1] 1 2 3
try(stabilize_ints(list("1", "a")))
#> Error in eval(expr, envir) : 
#>   `list("1", "a")` <list> must have every element satisfy `spec`.
#> ✖ Location 2: `list("1", "a")[[2]]` <character> must be coercible to <integer>
#>   (Locations: 1)