Consonance testing in R
'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.
The package can be installed through github.
library(devtools) install_github("tkonopka/consonance")
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:
%>%
)checkmate
and custom functions in consonance testslm
, glm
, etc.)Supplementary vignettes describe further topics:
Several other R packages handle testing, argument checking, and data validation. Some are listed here with a brief description.
consonance
.consonance
with a different syntaxA comparison of these packages in terms of performance is provided
in a vignette, performance.Rmd
.
Comments and contributions are welcome. Please raise an issue.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.