| stabilize_df | R Documentation |
stabilize_df() validates the structure and contents of a data frame. It can
check that specific named columns are present and valid, that extra columns
conform to a shared rule, that required column names are present, and that
the row count is within specified bounds. stabilise_df(),
stabilize_data_frame(), and stabilise_data_frame() are synonyms of
stabilize_df().
stabilize_df(
.x,
...,
.extra_cols = NULL,
.col_names = NULL,
.min_rows = NULL,
.max_rows = NULL,
.allow_null = TRUE,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
stabilise_df(
.x,
...,
.extra_cols = NULL,
.col_names = NULL,
.min_rows = NULL,
.max_rows = NULL,
.allow_null = TRUE,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
stabilize_data_frame(
.x,
...,
.extra_cols = NULL,
.col_names = NULL,
.min_rows = NULL,
.max_rows = NULL,
.allow_null = TRUE,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
stabilise_data_frame(
.x,
...,
.extra_cols = NULL,
.col_names = NULL,
.min_rows = NULL,
.max_rows = NULL,
.allow_null = TRUE,
.x_arg = caller_arg(.x),
.call = caller_env(),
.x_class = object_type(.x)
)
.x |
The argument to stabilize. |
... |
Named stabilizer functions, such as |
.extra_cols |
A single stabilizer function, such as a |
.col_names |
|
.min_rows |
|
.max_rows |
|
.allow_null |
|
.x_arg |
|
.call |
|
.x_class |
|
The validated data frame.
Other data frame functions:
specify_df(),
to_df()
Other stabilization functions:
stabilize_arg(),
stabilize_chr(),
stabilize_dbl(),
stabilize_fct(),
stabilize_int(),
stabilize_lgl(),
stabilize_lst(),
stabilize_present()
# Basic validation: required columns with type specs
stabilize_df(
data.frame(name = "Alice", age = 30L),
name = specify_chr_scalar(),
age = specify_int_scalar()
)
# Allow extra columns with .extra_cols
stabilize_df(
data.frame(name = "Alice", age = 30L, score = 99.5),
name = specify_chr_scalar(),
age = specify_int_scalar(),
.extra_cols = stabilize_present
)
# Check required column names without validating contents
stabilize_df(
mtcars,
.col_names = c("mpg", "cyl"),
.extra_cols = stabilize_present
)
# Enforce row count constraints
try(stabilize_df(mtcars[0, ], .min_rows = 1, .extra_cols = stabilize_present))
# NULL is allowed by default
stabilize_df(NULL)
try(stabilize_df(NULL, .allow_null = FALSE))
# Coercible inputs such as named lists are accepted
stabilize_df(
list(name = "Alice", age = 30L),
name = specify_chr_scalar(),
age = specify_int_scalar()
)
# Non-coercible inputs are rejected
try(stabilize_df("not a data frame"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.