Commit 081a9210 authored by houyun's avatar houyun
Browse files

copy new_data_frame from ggplot2

parent 68ff2b40
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -15,8 +15,31 @@ aes_modify <- function (aes1, aes2)
  aes
}

# Note: copy from ggplot2 (3.3.6)
#' @noRd
new_data_frame <- getFromNamespace("new_data_frame", "ggplot2")
new_data_frame <- function (x = list(), n = NULL)
  {
    if (length(x) != 0 && is.null(names(x))) {
      stop("Elements must be named", call. = FALSE)
    }
    lengths <- vapply(x, length, integer(1))
    if (is.null(n)) {
      n <- if (length(x) == 0 || min(lengths) == 0)
        0
      else max(lengths)
    }
    for (i in seq_along(x)) {
      if (lengths[i] == n)
        next
      if (lengths[i] != 1) {
        stop("Elements must equal the number of rows or 1", call. = FALSE)
      }
      x[[i]] <- rep(x[[i]], n)
    }
    class(x) <- "data.frame"
    attr(x, "row.names") <- .set_row_names(n)
    x
  }

#' @noRd
aes_vars <- function(mapping, vars) {