Use ? to set a function's return type, argument types, or variable types in the body of the function.

`?`(lhs, rhs)

check_output(.output, .assertion, ...)

check_arg(.arg, .assertion, ..., .bind = FALSE)

declare(x, assertion, value, const = FALSE)

Arguments

lhs

lhs

rhs

rhs

.output

function output

.assertion

an assertion

...

additional arguments passed to assertion

.arg

function argument

.bind

whether to actively bind the argument so it cannot be modified unless it satisfies the assertion

x

variable name as a string

assertion

a function

value

an optional value

const

whether to declare x as a constant

Examples

numeric ? function (x= ?numeric) { numeric ? y <- 2 res <- x + y res }
#> # typed function #> function (x) #> { #> check_arg(x, numeric) #> declare("y", numeric, value = 2) #> res <- x + y #> check_output(res, numeric) #> } #> <environment: 0x000000002b89e240> #> # Return type: numeric #> # Arg types: #> # x: numeric