type_check: List Type Checking

View source: R/type_check.R

type_checkR Documentation

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
  • A named list to use as a template.

target
  • A named list to use as the output.

with_cast
  • If true, edits the target instead of just checking types.

log_items
  • Which debug info to print. Takes a character vector. By default, logs casts and excess fields (target fields not in template). We expect some missing for the moment.

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
)

structenforcement documentation built on June 8, 2025, 11:49 a.m.