1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#' @rdname Truth
#' @export
is_false <- function(x, .xname = get_name_in_parent(x))
{
x <- coerce_to(x, "logical", .xname)
call_and_name(
function(x)
{
is_na_x <- is.na(x)
ok <- !(x | is_na_x) # same as !x & !is_na_x
set_cause(ok, ifelse(is_na_x, "missing", "true"))
},
x
)
}
#' @rdname Truth
#' @export
is_na <- function(x, coerce_to_logical = FALSE, .xname = get_name_in_parent(x))
{
call_and_name(
function(x)
{
if(coerce_to_logical)
{
x <- coerce_to(x, "logical", .xname)
}
ok <- is.na(x)
if(is.logical(x))
{
set_cause(ok, ifelse(x, "true", "false"))
} else
{
set_cause(ok, "not missing")
}
},
x
)
}
#' @rdname Truth
#' @export
is_not_na <- function(x, coerce_to_logical = FALSE, .xname = get_name_in_parent(x))
{
call_and_name(
function(x)
{
if(coerce_to_logical)
{
x <- coerce_to(x, "logical", .xname)
}
ok <- !is.na(x)
set_cause(ok, "missing")
},
x
)
}
#' @rdname Truth
#' @export
is_not_false <- function(x, .xname = get_name_in_parent(x))
{
x <- coerce_to(x, "logical", get_name_in_parent(x))
call_and_name(
function(x)
{
ok <- x | is.na(x)
set_cause(ok, "false")
},
x
)
}
#' @rdname Truth
#' @export
is_not_true <- function(x, .xname = get_name_in_parent(x))
{
x <- coerce_to(x, "logical", .xname)
call_and_name(
function(x)
{
ok <- !x | is.na(x)
set_cause(ok, "true")
},
x
)
}
#' @rdname Truth
#' @export
is_true <- function(x, .xname = get_name_in_parent(x))
{
x <- coerce_to(x, "logical", .xname)
call_and_name(
function(x)
{
is_na_x <- is.na(x)
ok <- x & !is_na_x
set_cause(ok, ifelse(is_na_x, "missing", "false"))
},
x
)
}
|