specify_lst() creates a function that will call stabilize_lst() with the
provided arguments. specify_list() is a synonym of specify_lst().
Usage
specify_lst(
...,
.named = NULL,
.unnamed = NULL,
.allow_null = TRUE,
.min_size = NULL,
.max_size = NULL
)
specify_list(
...,
.named = NULL,
.unnamed = NULL,
.allow_null = TRUE,
.min_size = NULL,
.max_size = NULL
)Arguments
- ...
Named stabilizer functions, such as
stabilize_*functions (stabilize_chr(), etc) or functions produced byspecify_*()functions (specify_chr(), etc). Each name corresponds to a required element in.x, and the function is used to validate that element.- .named
A single stabilizer function, such as a
stabilize_*function (stabilize_chr(), etc) or a function produced by aspecify_*()function (specify_chr(), etc). This function is used to validate all named elements of.xthat are not explicitly listed in.... IfNULL(default), any extra named elements will cause an error.- .unnamed
A single stabilizer function, such as a
stabilize_*function (stabilize_chr(), etc) or a function produced by aspecify_*()function (specify_chr(), etc). This function is used to validate all unnamed elements of.x. IfNULL(default), any unnamed elements will cause an error.- .allow_null
(length-1 logical)Is NULL an acceptable value?- .min_size
(length-1 integer)The minimum size of the object. Object size will be tested usingvctrs::vec_size().- .max_size
(length-1 integer)The maximum size of the object. Object size will be tested usingvctrs::vec_size().
Value
A function of class "stbl_specified_fn" that calls
stabilize_lst() with the provided arguments. The generated function will
also accept ... for additional named element specifications to pass to
stabilize_lst(). You can copy/paste the body of the resulting function if
you want to provide additional context or functionality.
See also
Other list functions:
stabilize_lst(),
stabilize_present(),
to_lst()
Other specification functions:
specify_chr(),
specify_dbl(),
specify_df(),
specify_fct(),
specify_int(),
specify_lgl()
Examples
stabilize_config <- specify_lst(
name = specify_chr_scalar(allow_na = FALSE),
version = stabilize_int_scalar,
debug = specify_lgl_scalar(allow_na = FALSE),
.unnamed = stabilize_chr_scalar
)
stabilize_config(list(name = "myapp", version = 1L, debug = FALSE, "extra"))
#> $name
#> [1] "myapp"
#>
#> $version
#> [1] 1
#>
#> $debug
#> [1] FALSE
#>
#> [[4]]
#> [1] "extra"
#>
try(
stabilize_config(
list(name = "myapp", version = 1L, debug = FALSE, c("a", "b"))
)
)
#> Error in eval(expr, envir) :
#> `list(name = "myapp", version = 1L, debug = FALSE, c("a", "b"))[[4]]`
#> must be a single <character>.
#> ✖ `list(name = "myapp", version = 1L, debug = FALSE, c("a", "b"))[[4]]` has 2
#> values.