R/bind_bootstrap_score.R

Defines functions bind_bootstrap_score

Documented in bind_bootstrap_score

#' Title
#'
#' @param ...
#'
#' @return
#' @export
#'
#' @examples
bind_bootstrap_score <- function(...) {

  check_class <- function(x) {
    inherits(x, "harp_bootstrap")
  }

  dots <- list(...)
  if (length(dots) == 1) dots <- dots[[1]]

  dots <- dots[sapply(dots, function(x) !is.null(x))]
  if (!all(sapply(dots, check_class))) {
    bad_classes <- which(!sapply(dots, check_class))
    bad_classes <- paste0("..", paste(bad_classes, sep = ", .."))
    stop(
      bad_classes, " are not 'harp_bootstrap' objects.\n",
      "Only outputs of 'bootstrap_score()' and 'pooled_bootstrap_score()' can be used."
    )
  }

  if (length(dots) == 1) return(dots[[1]])

  list_names <- unique(unlist(lapply(dots, names)))

  res <- lapply(
    list_names,
    function(x) Reduce(rbind, lapply(dots, function(y) y[[x]]))
  )

  names(res) <- list_names

  new_harp_bootstrap(res)

}
andrew-MET/harpPoint documentation built on Feb. 23, 2023, 1:06 a.m.