| Title: | Struct-Like Data Type Checking and Enforcement |
| Version: | 0.3.0 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Suggests: | lubridate, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Imports: | rlang |
| NeedsCompilation: | yes |
| Packaged: | 2026-06-30 06:32:43 UTC; yakumo |
| Author: | Samuel Sapire [aut, cre, cph], Sean Barrett [ctb] |
| Maintainer: | Samuel Sapire <sapires@protonmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-06-30 06:50:02 UTC |
Bind as Struct
Description
Given a set of lists/dataframes, attempt to join them as a dataframe with field types matching the specified template. The default approach uses all fields present in the input lists, while the strict mode ensures that the template fields and only the template fields are present.
Usage
bind_as_struct(template, ..., .list = NULL, strict = FALSE)
Arguments
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 |
Value
A dataframe containing the combined inputs.
Examples
bind_as_struct(list("a" = character(0)), list("a" = 1), list("a" = "a"))
List Type Checking
Description
Given two named objects, go through both and make the types of the second match the types of the first.
Usage
type_check(
template,
target,
with_cast = FALSE,
log_items = c("casts", "missing", "excess", "debug")[c(1, 3)]
)
Arguments
template |
|
target |
|
with_cast |
|
log_items |
|
Value
The target object, with its types appropriately cast.
Examples
type_check(
list("a" = character(0), "b" = integer(0)),
data.frame("a" = c(1,2), "b" = c(3,4)),
TRUE, NULL
)
Vectorised List Type Checking
Description
Apply type_check to each element in a list of targets against a single
template. The template lookup table is built once and reused across every
target, amortising the hash-table construction.
Usage
type_check_each(
template,
targets,
with_cast = FALSE,
log_items = c("casts", "missing", "excess", "debug")[c(1, 3)]
)
Arguments
template |
A named list to use as a template. |
targets |
A list of named lists/dataframes to check against the template. |
with_cast |
If true, edits each target instead of just checking types. |
log_items |
Which debug info to print. Mirrors |
Value
A list of the targets, with their types appropriately cast. Names of targets are preserved.
Examples
type_check_each(
list("a" = character(0), "b" = integer(0)),
list(list("a" = 1, "b" = 2.5), list("a" = "x", "b" = 3L)),
TRUE, NULL
)