R/draw_one_sample_safely.R

Defines functions draw_one_sample_safely

# internal function to ensure that drawing from a vector that may have only one element works properly
draw_one_sample_safely <- function(v) {
  if (length(v) == 0)
    stop('try to draw sample from empty vector')
  if (length(v) == 1)
    return(v[1])
  else
    return(sample(v, 1))
}
biomedbigdata/ASimulatoR documentation built on Sept. 6, 2022, 7:55 p.m.