Skip to contents

std_lgl() converts other classes to logical vectors. All but character use as.logical(); character vectors are converted by first (optionally) standardizing with std_chr and then assigning logical value based on the regular expression in true, false, and na.

Usage

std_lgl(
  x,
  true = c("^TRUE$", "^1$", "^YES", "^POS", "^ALIVE", "^ON THERAPY"),
  false = c("^FALSE$", "^0$", "^NO", "^NEG", "^EXPIRED", "^DECEASED", "^OFF THERAPY"),
  na = na_patterns,
  std_chr = TRUE,
  warn = TRUE
)

Arguments

x

A vector to convert

true

Regex patterns to consider TRUE. Passed to stringr::str_detect(). Can be a vector of patterns.

false

Regex patterns to consider FALSE. Passed to stringr::str_detect(). Can be a vector of patterns.

na

Regex patterns to consider NA. Passed to stringr::str_detect(). Can be a vector of patterns.

std_chr

Whether to standardized a character vector before parsing

warn

Whether to warn if character strings were not converted to logical

Value

A logical vector