Skip to contents

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

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

lax({
  sample(5:3)
  sample(5:4)
  sample(5:5)

  diag(5:3)
  diag(5:4)
  diag(5:5)
})
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    0    0    0
#> [2,]    0    1    0    0    0
#> [3,]    0    0    1    0    0
#> [4,]    0    0    0    1    0
#> [5,]    0    0    0    0    1

if (FALSE) { # \dontrun{
  sample(5:5)
  diag(5)
} # }