1#' Split array, apply function, and return results in a data frame.
2#'
3#' For each slice of an array, apply function then combine results into a data
4#' frame.
5#'
6#' @template ply
7#' @template a-
8#' @template -d
9#' @param .id name(s) of the index column(s).
10#'   Pass \code{NULL} to avoid creation of the index column(s).
11#'   Omit or pass \code{NA} to use the default names
12#'   \code{"X1"}, \code{"X2"}, \ldots.
13#'   Otherwise, this argument must have the same length as
14#'   \code{.margins}.
15#' @export
16adply <- function(.data, .margins, .fun = NULL, ..., .expand = TRUE,
17                  .progress = "none", .inform = FALSE, .parallel = FALSE,
18                  .paropts = NULL, .id = NA) {
19  pieces <- splitter_a(.data, .margins, .expand, .id)
20  .id <- NA
21  if (is.null(attr(pieces, "split_labels"))) {
22    .id <- NULL
23  }
24
25  ldply(.data = pieces, .fun = .fun, ...,
26    .progress = .progress, .inform = .inform,
27    .parallel = .parallel, .paropts = .paropts,
28    .id = .id)
29}
30