Skip to contents

Simulate a vector of random logical values. Provides the option of inserting base::NA or returning base::NULL or zero-length logical.

Usage

sim_logical(
  prob_true = 0.5,
  length = c(1, 10),
  prob_na = 0,
  n_na = 1L,
  prob_null = 0,
  prob_zero_length = 0,
  names = FALSE
)

Arguments

prob_true

(Scalar numeric: [0, 1])
The probability of sampling TRUE. The probability of sampling FALSE is 1 - prob_true.

length

(integer vector of length 1 or 2)
The number of elements in the simulated vector. If length(length)==1L, sets the number of elements to length. If length(length)==2L, randomly selects the number of elements from the interval [min, max].

prob_na

(Scalar numeric: [0, 1])
The probability of inserting an NA.

n_na

(Scalar integer: [0, Inf])
The number of NAs to insert.

prob_null

(Scalar numeric: [0, 1])
The probability of returning a NULL object.

prob_zero_length

(Scalar numeric: [0, 1])
The probability of returning a zero-length vector.

names

(Scalar logical: c(TRUE, FALSE))
Whether or not the vector should have names. TRUE (default) sets names as name_1, name_2, name_3, ...

Value

logical

Examples

#----------------------------------------------------------------------------
# sim_logical() examples
#----------------------------------------------------------------------------
library(bkcheck)

sim_logical()
#> [1]  TRUE FALSE FALSE FALSE FALSE FALSE
sim_logical(prob_na = 1)
#> [1] FALSE  TRUE  TRUE  TRUE FALSE    NA
sim_logical(prob_null = 1)
#> NULL
sim_logical(prob_zero_length = 1)
#> logical(0)
sim_logical(names = TRUE)
#> name_1 
#>  FALSE