Struct-Like Data Type Checking and Enforcement

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.


structenforcement

pipeline status coverage report Latest Release

Tools for ensuring that data is correctly typed.

Without moving over to a strict type system such at that offered by the typed package or enforcing classes everywhere, this offers a straightforward approach to getting lists (and especially dataframes) into the correct types, where R's extreme dynamism might infer something incorrectly when it comes to input data.

It is naturally best used in conjunction with other means of ensuring that structures keep the correct types once they've been cast. As of the initial implementation, this mostly cares about primitive types. The only class that is handled neatly is POSIXct.

Installation

You can install the development version of structenforcement like so:

remotes::install_gitlab("S_S_/structenforcement")

Example

library(structenforcement)

template_struct <- data.frame(
    "Sepal.Length"  = integer(0),
    "Sepal.Width"   = numeric(0),
    "Petal.Length"  = numeric(0),
    "Petal.Width"   = numeric(0)
)
type_checked_iris <- type_check(
    template_struct,
    iris,
    TRUE,
    c("casts", "missing", "excess")
)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("structenforcement")

0.3.1 by Samuel Sapire, 3 months ago


Browse source code at https://github.com/cran/structenforcement


Authors: Samuel Sapire [aut, cre, cph] , Sean Barrett [ctb]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports rlang

Suggests lubridate, testthat


See at CRAN