safe_sample: Safe version of R sample function

safe_sampleR Documentation

Safe version of R sample function

Description

2015 04 08 - BTL I just got bitten very badly by the incredibly annoying behavior of R's sample() function, so here is a replacement function that I need to use everywhere now. When I called sample with a vector that sometimes had length n=1, it sampled from 1:n instead of returning the single value. This majorly screwed all kinds of things in a very subtle, very hard to find way.

Usage

safe_sample(x, ...)

Arguments

x

Either a vector of one or more elements from which to choose, or a positive integer.

...

Arguments that can be passed on to base::sample()

Value

Returns a value that is probably an integer but is definitely not null


langfob/bdpg documentation built on Dec. 8, 2022, 5:33 a.m.