R/utils-ply.R

Defines functions map lst_xtr dbl_xtr int_xtr lgl_xtr chr_xtr dbl_mply int_mply lgl_mply chr_mply dbl_ply int_ply lgl_ply chr_ply

chr_ply <- function(x, fun, ..., length = 1L, use_names = FALSE) {
  vapply(x, fun, character(length), ..., USE.NAMES = use_names)
}

#' @keywords internal
lgl_ply <- function(x, fun, ..., length = 1L, use_names = FALSE) {
  vapply(x, fun, logical(length), ..., USE.NAMES = use_names)
}

int_ply <- function(x, fun, ..., length = 1L, use_names = FALSE) {
  vapply(x, fun, integer(length), ..., USE.NAMES = use_names)
}

dbl_ply <- function(x, fun, ..., length = 1L, use_names = FALSE) {
  vapply(x, fun, double(length), ..., USE.NAMES = use_names)
}

chr_mply <- function(...) {
  chr_ply(map(...), identity)
}

lgl_mply <- function(...) {
  lgl_ply(map(...), identity)
}

int_mply <- function(...) {
  int_ply(map(...), identity)
}

dbl_mply <- function(...) {
  dbl_ply(map(...), identity)
}

chr_xtr <- function(x, i, ...) chr_ply(x, `[[`, i, ...)

lgl_xtr <- function(x, i, ...) lgl_ply(x, `[[`, i, ...)

int_xtr <- function(x, i, ...) int_ply(x, `[[`, i, ...)

dbl_xtr <- function(x, i, ...) dbl_ply(x, `[[`, i, ...)

lst_xtr <- function(x, ...) {

  for (i in c(...)) {
    x <- lapply(x, `[[`, i)
  }

  x
}

map <- function(f, ..., use_names = FALSE) Map(f, ..., USE.NAMES = use_names)

Try the blockr.core package in your browser

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

blockr.core documentation built on June 8, 2025, 1:43 p.m.