| Title: | Struct-Like Data Type Checking and Enforcement |
|---|---|
| Description: | Enforcement of field types in lists. A drop-in tool to allow for dynamic input data that might be questionably parsed or cast to be coerced into the specific desired format in a reasonably performant manner. |
| Authors: | Samuel Sapire [aut, cre, cph], Sean Barrett [ctb] |
| Maintainer: | Samuel Sapire <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-07 09:36:48 UTC |
| Source: | https://github.com/cran/structenforcement |
Given a set of lists/dataframes, attempt to join them as a dataframe with field
types matching the specified template. The default and fastest approach simply
relies on dplyr::bind_rows to use all fields present in the lists to be
joined, while strict mode ensures that the template fields and only the template
fields are present.
bind_as_struct(template, ..., .list = NULL, strict = FALSE)bind_as_struct(template, ..., .list = NULL, strict = FALSE)
template |
A named list to use as a template. |
... |
The lists to join |
.list |
A pre-built list of frames to join, as an alternative to |
strict |
Use all and only the fields in the template. Default: FALSE |
A dataframe containing the combined inputs.
bind_as_struct(list("a" = character(0)), list("a" = 1), list("a" = "a"))bind_as_struct(list("a" = character(0)), list("a" = 1), list("a" = "a"))
Given two named objects, go through both and make the types of the second match the types of the first.
type_check( template, target, with_cast = FALSE, log_items = c("casts", "missing", "excess", "debug")[c(1, 3)] )type_check( template, target, with_cast = FALSE, log_items = c("casts", "missing", "excess", "debug")[c(1, 3)] )
template |
|
target |
|
with_cast |
|
log_items |
|
The target object, with its types appropriately cast.
type_check( list("a" = character(0), "b" = integer(0)), data.frame("a" = c(1,2), "b" = c(3,4)), TRUE, NULL )type_check( list("a" = character(0), "b" = integer(0)), data.frame("a" = c(1,2), "b" = c(3,4)), TRUE, NULL )