declare: Type-check a function parameter

View source: R/declare.R

declareR Documentation

Type-check a function parameter

Description

Stops if variable type is wrong.

Usage

declare(..., ..env = parent.frame())

decl(x, pred)

Arguments

...

Parameters of the form name="type" or even name="type1|type2|..."

x

Variable to be type-checked

pred

A type checking predicate, such as is.character or is.data.frame (function)

Details

decl is a simple, fast type checker, and should be used when speed matters, such as in low-level functions. declare is more powerful and implements a convenient syntax for richer types.

Value

decl returns its first argument. declare returns NULL invisibly. In any event, both functions halt on type errors.


pteetor/tutils documentation built on April 25, 2024, 9:14 a.m.