/checkmate

Fast and versatile argument checks

Primary LanguageROtherNOASSERTION

checkmate

CRAN Build Status Build status Coverage Status

Fast and versatile argument checks for R.

Ever used an R function that produced a not-very-helpful error message, just to discover after minutes of debugging that you simply passed a wrong argument?

Blaming the laziness of the package author for not doing such standard checks (in a dynamically typed language such as R) is at least partially unfair, as R makes theses types of checks cumbersome and annoying. Well, that's how it was in the past.

Enter checkmate.

Virtually every standard type of user error when passing arguments into function can be caught with a simple, readable line which produces an informative error message in case. A substantial part of the package was written in C to minimize any worries about execution time overhead.

Here is an overview of the most useful functions for argument checking:

Scalars / Single Objects:

What can be checked: Simple, non-NA scalars and objects of a specific class.

Choices and Subsets

What can be checked: Choices like "A", "B" or "C", subset of those or set equality.

Vectors and factors:

What can be checked: Length, upper and lower bounds, NAs, duplicates, names.

Matrices, Arrays and Data Frame:

What can be checked: Storage mode (numeric, char, etc.), number of rows, cols, NAs, names.

Lists and Environments:

What can be checked: length, element type, names.

Functions:

What can be checked: Arguments and ordered arguments.

File IO:

What can be checked: Path exists, is accessible.

In case you miss flexibility:

Perform multiple checks at once and throw an assertion if all checks fail.

Argument Checks for the Lazy

These functions allow a special syntax to define argument checks using a special pattern. E.g., qassert(x, "I+") asserts that x is an integer vector with at least one element and no missing values. This provide a completely alternative mini-language (or style) how to perform argument checks. You choose what you like best.