R/logicaltests.R

Defines functions anyj allj

Documented in allj anyj

#' Logical tests
#'
#' @export
#' @name logicaltests
#' @param .data input. This can be JSON input, or an object of class
#' \code{jqr} that has JSON and query params combined, which is passed
#' from function to function when using the jqr DSL.
#' @examples
#' # any
#' '[true, false]' %>% anyj
#' '[false, false]' %>% anyj
#' '[]' %>% anyj
#'
#' # all
#' '[true, false]' %>% allj
#' '[true, true]' %>% allj
#' '[]' %>% allj
#'
#' ## many JSON inputs
#' '[true, false] [true, true] [false, false]' %>% anyj
#' '[true, false] [true, true] [false, false]' %>% allj

#' @export
#' @rdname logicaltests
allj <- function(.data) {
  pipe_autoexec(toggle = TRUE)
  dots <- comb(tryargs(.data), structure('all', type = "all"))
  structure(list(data = getdata(.data), args = dots), class = "jqr")
}

#' @export
#' @rdname logicaltests
anyj <- function(.data) {
  pipe_autoexec(toggle = TRUE)
  dots <- comb(tryargs(.data), structure('any', type = "any"))
  structure(list(data = getdata(.data), args = dots), class = "jqr")
}
ropensci/jqr documentation built on Jan. 19, 2024, 8:33 p.m.