View source: R/make_chr_logi.R
make_chr_logi | R Documentation |
Transform a character into logical with denoted values as TRUE, with NA handling options
make_chr_logi(x, val_as_TRUE = NULL, preserve_NA = TRUE, NA_as_what = NA)
x |
Input character vector to coerce to logical |
val_as_TRUE |
A character vector containing the values to coerce to TRUE. Including |
preserve_NA |
Should |
NA_as_what |
How should |
This function is most useful for its explicit handling of NA
. By default, NA
is
passed-through. If NA
is included within val_as_TRUE, then all NA
will be
set to TRUE
. Alternatively, if preserve_NA is set to FALSE
and NA_as_what
is set to either TRUE
or FALSE
, NA
will be set as requested.
Non-character inputs to either x or val_as_TRUE will raise an error. Furthermore,
if x is all NA
, an error is raised.
A logical vector of length x
x <- c("yes", "YES", NA, "no", "NO", "NA", "0") make_chr_logi(x, c("yes", "YES")) make_chr_logi(x, c("yes", "YES", NA)) # overrides preserve_NA or NA_as_what
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.