Commit cbeb953e authored by houyun's avatar houyun
Browse files

keep tree attributes

parent 3823e25d
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -25,8 +25,18 @@ as_matrix_data.matrix <- function(x,
    name <- deparse(substitute(x))
  }

  x <- rlang::set_names(list(x), name)
  matrix_data(x, group = group, ...)
  if (!is.null(group)) {
    row_tree <- col_tree <- NULL
  } else {
    row_tree <- attr(x, "row_tree")
    col_tree <- attr(x, "col_tree")
  }

  x <- matrix_data(rlang::set_names(list(x), name),
                   group = group, ...)
  attr(x, "row_tree") <- row_tree
  attr(x, "col_tree") <- col_tree
  x
}

#' @param include one of "numeric" (default), "character" or "factor".
@@ -55,6 +65,8 @@ as_matrix_data.data.frame <- function(x,
as_matrix_data.correlate <- function(x,
                                     extra_mat = list(),
                                     ...) {
  row_tree <- attr(x, "row_tree")
  col_tree <- attr(x, "col_tree")
  id <- vapply(x, is.null, logical(1))
  x <- x[!id]
  if(length(extra_mat) > 0) {
@@ -65,6 +77,8 @@ as_matrix_data.correlate <- function(x,
  }
  x <- matrix_data(x, group = NULL, ...)
  class(x) <- c("cor_matrix_data", class(x))
  attr(x, "row_tree") <- row_tree
  attr(x, "col_tree") <- col_tree
  x
}

+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ as_md_tbl.matrix_data <- function(x, ...)
  md_tbl <- structure(.Data = bind_cols(id, value),
                      row_names = row_names(x),
                      col_names = col_names(x),
                      row_tree = attr(x, "row_tree"),
                      col_tree = attr(x, "col_tree"),
                      type = type,
                      diag = diag,
                      class = c("md_tbl", "tbl_df", "tbl", "data.frame"))