Attachment 'helpers.R'
Download 1 #' Are Some or No Values True?
2 #'
3 #' Given a set of logical vectors, check if some or all values false.
4 #'
5 #' These functions are to compliment \code{\link[base:all]{all}} and \code{\link[base:any]{any}}. Refer to the respective help pages for those functons for more details.
6 #' @param ... zero or more logical vectors. Other objects of zero length are ignored, and the rest are coerced to logical ignoring any class.
7 #' @param na.rm logical: if true, NA values are removed before the result is computed.
8 #' @return
9 #' \describe{
10 #' \item{\code{some}}{returns \code{TRUE} only if some but not all values are \code{TRUE}. If no values provided, \code{FALSE} is returned. If the values provided include one or more \code{NA} values, \code{TRUE} is still only returned if at least one \code{TRUE} and one \code{FALSE} values. Otherwise \code{NA} is returned (unless \code{na.rm = TRUE}).}
11 #' \item{\code{none}}{returns \code{TRUE} only if no value is \code{TRUE}, including when no values provided. The latter is the distinction from \code{!all()}, which returns \code{FALSE} when no values are provided. If the values provided include one or more \code{NA} values, \code{FALSE} is returned if at least one value is \code{TRUE}. Otherwise \code{NA} is returned (unless \code{na.rm = TRUE}).}
12 #' }
13 #' @name checks
14 #' @examples
15 #' some(c(T, F, F)) # TRUE
16 #' some(c(T, T, T)) # FALSE because all TRUE
17 #' some(c(F, F, F)) # FALSE
18 #' some() # FALSE
19 #'
20 #' none(c(F, F, F)) # TRUE
21 #' none(c(T, F, F)) # FALSE
22 #' none() # TRUE
23 NULL
24
25 #' @rdname checks
26 #' @export
27 some <- function(..., na.rm = FALSE) {
28 any(..., na.rm = na.rm) && !all(..., na.rm = na.rm)
29 }
30
31 #' @rdname checks
32 #' @export
33 none <- function(..., na.rm = FALSE) {
34 is.null(c(...)) || !any(..., na.rm = na.rm)
35 }
You are not allowed to attach a file to this page.