R/which3.R

Defines functions which3

Documented in which3

#' which of three vectors are the elements (all, any) true?
#' @param x,y,z Logical vectors. Either the same length or length-1
#' @param And Boolean. If \code{TRUE}, only indices where all of x, y, z
#' are TRUE are returned; if \code{FALSE}, any index where x, y, z
#' are TRUE are returned.
#' @param anyNAx,anyNAy,anyNAz Whether or not the inputs have \code{NA}.
#' @export

which3 <- function(x, y, z,
                   And = TRUE,
                   anyNAx = anyNA(x),
                   anyNAy = anyNA(y),
                   anyNAz = anyNA(z)) {
  stopifnot(is.logical(x), is.logical(y), is.logical(z))
  check_TF(And)
  if (anyNAx || anyNAy || anyNAz) {
    cpp_list <- .Call("Cwhich3", x, y, z, And, anyNAx, anyNAy, anyNAz, PACKAGE = packageName)
    {cpp_list[[2]]}[seq_len(cpp_list[[1]])]
  } else {
    .Call("Cwhich3_mem", x, y, z, And, PACKAGE = packageName)
  }
}

Try the hutilscpp package in your browser

Any scripts or data that you put into this service are public.

hutilscpp documentation built on Oct. 11, 2023, 9:06 a.m.