consonance

Consonance testing in R

Status codecov

'Consonance' means accord or agreement. This R package associates the term 'consonance testing' to the process of determining that a dataset is compatible with predefined criteria. This type of testing can be used, for example, to determine if a new dataset should proceed to statistical analysis or if a new dataset satisfies the assumptions built into a trained model.

Consonance testing is related to unit testing and argument testing. The distinction is that consonance testing is relevant during data analysis rather than during software development. Accordingly, the consonance package provides a syntax and features that are geared toward interactive uses and toward pipelines.

Installation

The package can be installed through github.

library(devtools)
install_github("tkonopka/consonance")

Usage

For a minimal usage example, consider a small data frame with a character-class column (id) and a numeric-class column (value).

example_data <- data.frame(id=c("a", "b"), value=c(1, 2), stringsAsFactors=FALSE)
example_data

The package can be used to create a suite of tests.

library(consonance)
suite <- consonance_test("id column character", is.character, .var="id") +
  consonance_test("value numeric", is.numeric, .var="value")
suite

The data can then be evaluated against the suite.

# with default settings, validation of consonant data is quiet
validate(example_data, suite)
# logging can be activated to provide verbose messages
validate(example_data, suite, logging.level="INFO")

When the data object does not meet the consonance criteria, the validation step provides log messages and halts execution.

validate(example_data[, "id", drop=FALSE], suite)

The package vignettes explain more package features, including:

Supplementary vignettes describe further topics:

Related work

Several other R packages handle testing, argument checking, and data validation. Some are listed here with a brief description.

A comparison of these packages in terms of performance is provided in a vignette, performance.Rmd.

Contributing

Comments and contributions are welcome. Please raise an issue.



tkonopka/consonance documentation built on Oct. 9, 2020, 2:09 p.m.