tobool {easyr}R Documentation

Convert to Logical/Boolean

Description

Flexible boolean conversion. Author: Bryce Chamberlain.

Usage

tobool(
  x,
  preprocessed.values = NULL,
  nastrings = easyr::nastrings,
  ifna = c("return-unchanged", "error", "warning", "return-na"),
  verbose = TRUE,
  true.vals = c("true", "1", "t", "yes"),
  false.vals = c("false", "0", "f", "no")
)

Arguments

x

Value or vector to be converted.

preprocessed.values

Strings need to have NAs set, lowercase and be trimmed before they can be checked. To avoid doing this multiple times, you can pass these processed values to the function.

nastrings

Vector of characters to be considered NAs. todate will treat these like NAs. Defaults to the easyr::nastrings list.

ifna

Action to take if NAs are created. 'return-unchanged' returns the sent vector unchanged; 'warning' results in a warning and returns the converted vector with new NAs; 'error' results in an error.

verbose

Choose to view messaging.

true.vals

Values to consider as TRUE.

false.vals

Values to consider as FALSE.

Value

Converted logical vector.

Examples

tobool( c( 'true', 'FALSE', 0, 1, NA, 'yes', 'NO' ) )

[Package easyr version 0.5-8 Index]