R/sameDims.R

Defines functions sameDims

Documented in sameDims

#' sameDims
#'
#' Checks whether magpie objects have the same items in every dimension (ignoring order).
#'
#' @param ... Various magpie objects
#'
#' @returns A logical indicating whether the magpie objects have the same items in every dimension.
#' @author Pascal Sauer, Patrick Rein
#' @family ObjectInfo
#' @export
sameDims <- function(...) {
  magpies <- list(...)
  if (!all(vapply(magpies, is.magpie, logical(1)))) {
    stop("sameDims cannot handle non-magpie objects")
  }

  if (length(magpies) < 2) {
    return(TRUE)
  }

  .allSetequal <- function(vs) all(vapply(vs[-1], function(x) setequal(vs[[1]], x), logical(1)))
  return(.allSetequal(lapply(magpies, function(m) getItems(m, 1))) &&
           .allSetequal(lapply(magpies, function(m) getItems(m, 2))) &&
           .allSetequal(lapply(magpies, function(m) getItems(m, 3))))
}

Try the magclass package in your browser

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

magclass documentation built on April 17, 2026, 5:07 p.m.