View source: R/stabilize_lst.R
| stabilize_lst | R Documentation |
stabilize_lst() validates the structure and contents of a list. It can
check that specific named elements are present and valid, that extra named
elements conform to a shared rule, and that unnamed elements conform to a
shared rule. stabilise_lst(), stabilize_list(), and stabilise_list()
are synonyms of stabilize_lst().
stabilize_lst(
.x,
...,
.named = NULL,
.unnamed = NULL,
.allow_duplicate_names = FALSE,
.allow_null = TRUE,
.min_size = NULL,
.max_size = NULL,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
stabilize_list(
.x,
...,
.named = NULL,
.unnamed = NULL,
.allow_duplicate_names = FALSE,
.allow_null = TRUE,
.min_size = NULL,
.max_size = NULL,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
stabilise_lst(
.x,
...,
.named = NULL,
.unnamed = NULL,
.allow_duplicate_names = FALSE,
.allow_null = TRUE,
.min_size = NULL,
.max_size = NULL,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
stabilise_list(
.x,
...,
.named = NULL,
.unnamed = NULL,
.allow_duplicate_names = FALSE,
.allow_null = TRUE,
.min_size = NULL,
.max_size = NULL,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
.x |
The argument to stabilize. |
... |
Named stabilizer functions, such as |
.named |
A single stabilizer function, such as a |
.unnamed |
A single stabilizer function, such as a |
.allow_duplicate_names |
|
.allow_null |
|
.min_size |
|
.max_size |
|
.x_arg |
|
.call |
|
.x_class |
|
The validated list.
Other list functions:
specify_lst(),
stabilize_present(),
to_lst()
Other stabilization functions:
stabilize_arg(),
stabilize_chr(),
stabilize_dbl(),
stabilize_df(),
stabilize_fct(),
stabilize_int(),
stabilize_lgl(),
stabilize_present()
# Basic validation: named required elements
stabilize_lst(
list(name = "Alice", age = 30L),
name = specify_chr_scalar(),
age = specify_int_scalar()
)
# Allow any non-NULL element with stabilize_present
stabilize_lst(list(data = mtcars), data = stabilize_present)
# Allow extra named elements via .named
stabilize_lst(
list(a = 1L, b = 2L, c = 3L),
.named = specify_int_scalar()
)
# Allow unnamed elements via .unnamed
stabilize_lst(list(1L, 2L, 3L), .unnamed = specify_int_scalar())
# NULL is allowed by default
stabilize_lst(NULL)
try(stabilize_lst(NULL, .allow_null = FALSE))
# Enforce size constraints
try(stabilize_lst(list(a = 1L), .min_size = 2))
# Reject duplicate names by default; opt in to allow them
try(stabilize_lst(list(a = 1L, a = 2L), .named = specify_int_scalar()))
stabilize_lst(
list(a = 1L, a = 2L),
.named = specify_int_scalar(),
.allow_duplicate_names = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.