| data_column | R Documentation |
Creates a single column declaration used in ruleset(..., data_columns = ...).
Column declarations are schema checks (column existence, optionality, and
declared type), whereas rule() is for row-wise value checks.
data_column(
col,
type = NA_character_,
optional = FALSE,
description = NA_character_
)
col |
column name. |
type |
optional declared type (for example |
optional |
logical; if |
description |
optional free-text description. |
A data_column object (list) that can be passed in
ruleset(..., data_columns = list(...)).
rs <- ruleset(
rule(price >= 0),
data_columns = list(
data_column("price", type = "double", optional = FALSE),
data_column("note", type = "str", optional = TRUE)
)
)
rs
# combined with row rules and strict schema stopping
order_rules <- ruleset(
rule(price >= 0, allow_na = FALSE),
data_columns = list(
data_column("order_id", type = "int", optional = FALSE),
data_column("price", type = "double", optional = FALSE),
data_column("note", type = "str", optional = TRUE)
)
)
check_data(
data.frame(order_id = 1:3, price = c(10, 20, 30), note = c("ok", NA, "ok")),
order_rules,
stop_on_schema_fail = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.