Present since hutils v1.4.0. Same as sample, but avoiding the behaviour when length(x) == 1L.

samp(x, size = length(x), replace = size > length(x), loud = TRUE,
  prob = NULL)

Arguments

x

A vector.

size

A non-negative integer, the number of items to return.

replace

Should the sampling be done with replacement? Defaults to TRUE if size > length(x), with a message.

loud

If TRUE, the default, any behaviour known to be different from sample is flagged with a message.

prob

As in sample.

Examples

samp(1:5)
#> [1] 5 1 2 4 3
sample(1:5)
#> [1] 3 2 5 1 4
samp(1:5, size = 10) # no error
#> Using `replace = TRUE`.
#> [1] 4 3 2 5 2 5 3 4 1 5
tryCatch(sample(1:5, size = 10), error = function(e) print(e$m))
#> [1] "cannot take a sample larger than the population when 'replace = FALSE'"
samp(5, size = 3)
#> Using `replace = TRUE`.
#> `length(x) = 1`, so returning `rep.int(x, 3)`.
#> [1] 5 5 5
sample(5, size = 3)
#> [1] 1 5 2