guard: Mocking

Description Usage Arguments Examples

Description

Watches variables and function calls to check they are used correctly.

Usage

1
guard(f, verify, violate = stopifnot)

Arguments

f

a function whose introspection is watched.

verify

constraint that each variable or function call to be satisfied given as a list

violate

action when the verification is not passed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
f <- function(x, y) x + y
mf <- guard(f, list(x = quote(x > 2)))
mf(3, 1)
## Not run: 
mf(1, 2)

## End(Not run)

g <- function(z) f(z + 1, z - 1)
mg <- guard(g, list(f = list(x = quote(x > 1))))
mg(1)
## Not run: 
mg(0)

## End(Not run)

kos59125/Mock-n-Moll documentation built on May 20, 2019, 1:07 p.m.