strict_sample: Strict behaviour for functions with special scalar behaviour

Description Usage Arguments Examples

View source: R/shim-scalar.R

Description

[sample()] and [diag()] behave differently depending on whether their first argument is a scalar or a function. These shims throw an error when given a scalar to force you to pick a safer alternative.

Usage

1
2
3
strict_sample(x, size = length(x), replace = FALSE, prob = NULL)

strict_diag(x = 1, nrow, ncol)

Arguments

x, size, replace, prob, nrow, ncol

Passed on to [sample()] and [diag()]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
lax({
  sample(5:3)
  sample(5:4)
  sample(5:5)

  diag(5:3)
  diag(5:4)
  diag(5:5)
})

## Not run: 
  sample(5:5)
  diag(5)

## End(Not run)

hadley/strict documentation built on May 27, 2019, 7:26 a.m.