data_validator | R Documentation |
If you intend to use your dataclass to validate data frame like object such as tibbles, data frames, or data tables, pass the dataclass into this function to modify behavior.
data_validator(x, strict_cols = TRUE)
x |
A dataclass object |
strict_cols |
Should additional columns be allowed in the output? |
A function with the following properties:
A modified dataclass function designed to accept data frames
A single argument to test new data frames
Each column in a new data frame will be tested
An error occurs if new data passed to the returned function are invalid
Data is returned if new data passed to the returned function are valid
# Define a dataclass for creating data! Pass to data_validator():
my_df_dataclass <-
dataclass(
dte_col = dte_vec(),
chr_col = chr_vec(),
# Custom column validator ensures values are positive!
new_col = function(x) all(x > 0)
) |>
data_validator()
# Validate a data frame or data frame like objects!
data.frame(
dte_col = as.Date("2022-01-01"),
chr_col = "String!",
new_col = 100
) |>
my_df_dataclass()
# Allow additional columns in output
test_df_class <-
dataclass(
dte_col = dte_vec()
) |>
data_validator(strict_cols = FALSE)
tibble::tibble(
dte_col = as.Date("2022-01-01"),
other_col = "a"
) |>
test_df_class()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.