R/utilities-matrix.R

Defines functions interleave.default interleave.unit interleave cunion

# Col union
# Form the union of columns in a and b.  If there are columns of the same name in both a and b, take the column from a.
#
# @param data frame a
# @param data frame b
# @keyword internal
cunion <- function(a, b) {
  if (length(a) == 0) return(b)
  if (length(b) == 0) return(a)

  cbind(a, b[setdiff(names(b), names(a))])
}

# Interleave (or zip) multiple units into one vector
interleave <- function(...) UseMethod("interleave")
#' @export
interleave.unit <- function(...) {
  units <- lapply(list(...), as.list)
  interleaved_list <- interleave.default(!!!units)
  inject(unit.c(!!!interleaved_list))
}
#' @export
interleave.default <- function(...) {
  vec_interleave(...)
}

Try the ggplot2 package in your browser

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

ggplot2 documentation built on June 22, 2024, 11:35 a.m.