R/utils.R

Defines functions as_function deprecate inv_which ndots isFALSE `%||%` names2

#' Pipe operator
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL

names2 <- function(x) {
  names(x) %||% rep("", length(x))
}

`%||%` <- function(x, y) {
  if (is.null(x)) {
    y
  } else {
    x
  }
}

isFALSE <- function(x) identical(x, FALSE)

ndots <- function(...) nargs()

inv_which <- function(x, sel) {
  if (is.character(sel)) {
    names <- names(x)
    if (is.null(names)) {
      stop("character indexing requires a named object", call. = FALSE)
    }
    names %in% sel
  } else if (is.numeric(sel)) {
    seq_along(x) %in% sel
  } else {
    stop("unrecognised index type", call. = FALSE)
  }
}

deprecate <- function(...) {
  # No message for now
}

as_function <- function(...) {
  purrr::as_mapper(...)
}

Try the purrrlyr package in your browser

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

purrrlyr documentation built on March 29, 2022, 5:05 p.m.