R/fdid_list.R

Defines functions fdid_list

Documented in fdid_list

#' Create an `fdid_list` Object
#'
#' Bundles multiple `fdid` objects into a single list with class
#' `"fdid_list"` for convenient collective handling.
#'
#' @param ... One or more objects of class `"fdid"`, or a single list of them.
#' @param validate Logical; if `TRUE` (default) verify each element inherits
#'   from `"fdid"`.
#'
#' @return A list with classes `c("fdid_list", "list")`.
#'
#' @author Rivka Lipkovitz
#'
#' @export
fdid_list <- function(..., validate = TRUE) {
  x <- list(...)

  # Allow a single list input
  if (length(x) == 1L && is.list(x[[1]]) && !inherits(x[[1]], "fdid")) {
    x <- x[[1]]
  }

  if (validate) {
    bad <- !vapply(x, inherits, logical(1), "fdid")
    if (any(bad)) {
      stop(
        "All elements must inherit from class 'fdid'. ",
        "Invalid element(s): ", paste(which(bad), collapse = ", ")
      )
    }
  }

  class(x) <- c("fdid_list", "list")
  x
}

Try the fdid package in your browser

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

fdid documentation built on March 23, 2026, 5:07 p.m.