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.
Arguments
- spec
(function)A single stabilizer or coercion function, such as ato_*function (to_chr(), etc.), astabilize_*function (stabilize_chr(), etc.), or a function produced by aspecify_*()call (specify_chr(), etc.). Applied independently to each element ofx.
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.
See also
Other specification functions:
specify_all_of(),
specify_any_of(),
specify_chr(),
specify_date(),
specify_dbl(),
specify_df(),
specify_dttm(),
specify_dur(),
specify_fct(),
specify_int(),
specify_lgl(),
specify_lst(),
specify_one_of(),
specify_time()
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)