specify_df() creates a function that will call stabilize_df() with the
provided arguments. specify_data_frame() is a synonym of specify_df().
Usage
specify_df(
...,
.extra_cols = NULL,
.col_names = NULL,
.min_rows = NULL,
.max_rows = NULL,
.allow_null = TRUE
)
specify_data_frame(
...,
.extra_cols = NULL,
.col_names = NULL,
.min_rows = NULL,
.max_rows = NULL,
.allow_null = TRUE
)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 column in.x, and the function is used to validate that column.- .extra_cols
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 columns of.xthat are not explicitly listed in.... IfNULL(default), any extra columns will cause an error.- .col_names
(character)A character vector of column names that must be present in.x. Any columns listed here that are absent from.xwill cause an error. Unlike..., this does not validate the column contents.- .min_rows
(length-1 integer)The minimum number of rows allowed in.x. IfNULL(default), the row count is not checked.- .max_rows
(length-1 integer)The maximum number of rows allowed in.x. IfNULL(default), the row count is not checked.- .allow_null
(length-1 logical)Is NULL an acceptable value?
Value
A function of class "stbl_specified_fn" that calls
stabilize_df() with the provided arguments. The generated function will
also accept ... for additional named column specifications to pass to
stabilize_df(). You can copy/paste the body of the resulting function if
you want to provide additional context or functionality.
See also
Other data frame functions:
stabilize_df(),
to_df()
Other specification functions:
specify_chr(),
specify_dbl(),
specify_fct(),
specify_int(),
specify_lgl(),
specify_lst()
Examples
stabilize_person_df <- specify_df(
name = specify_chr_scalar(allow_na = FALSE),
age = specify_int_scalar(allow_na = FALSE),
.extra_cols = stabilize_present
)
stabilize_person_df(data.frame(name = "Alice", age = 30L, score = 99.5))
#> name age score
#> 1 Alice 30 99.5
try(stabilize_person_df(data.frame(name = "Alice")))
#> Error in eval(expr, envir) :
#> `data.frame(name = "Alice")` must contain element "age".