# 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()
Run the code above in your browser using DataLab