# Create a simple table with two
# columns: one `integer` and the
# other `character`
tbl <-
dplyr::tibble(
a = 1:5,
b = letters[1:5]
)
# Create a column schema object
# that describes the columns and
# their types (in the expected
# order)
schema_obj <-
col_schema(
a = "integer",
b = "character"
)
# Validate that the schema object
# `schema_obj` exactly defines
# the column names and column types
# of the `tbl` table
agent <-
create_agent(tbl = tbl) %>%
col_schema_match(schema_obj) %>%
interrogate()
# Determine if this validation step
# passed by using `all_passed()`
all_passed(agent)
# We can alternatively create
# a column schema object from a
# `tbl_df` object
schema_obj <-
col_schema(
.tbl = dplyr::tibble(
a = integer(0),
b = character(0)
)
)
# This should provide the same
# interrogation results as in the
# previous example
create_agent(tbl = tbl) %>%
col_schema_match(schema_obj) %>%
interrogate() %>%
all_passed()
Run the code above in your browser using DataLab