raincheck-package: Minimal deferred argument manipulation for R functions.

Description Author(s) Examples

Description

This package lets you write code to check and manage a function's arguments, but put that code outside the function for readability.

Author(s)

Gray Calhoun gcalhoun@iastate.edu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
f1 <- function(x) {
  FormatArguments_f1() # Yikes; *only* side effects
  ## Important, logical stuff goes here
  x[10,10]
} 

FormatArguments_f1 <- raincheck({
  if (!is.matrix(x)) {
    scold("'x' really should have been a matrix.")
    x <- as.matrix(x)
  }
  if (any(x == 30)) {
    scold("Cool, I love the number thirty.\n", "message")
  }
  if (nrow(x) < 10 || ncol(x) < 10) {
    scold("'x' must have at least 10 rows and 10 columns.", "stop")
  }
})

f1(matrix(30, 11, 11))
f1(matrix(31, 11, 11))

## Not run: f1(30)

grayclhn/raincheck documentation built on May 17, 2019, 8:34 a.m.