R/dt_row_groups.R

Defines functions dt_row_groups_init dt_row_groups_set dt_row_groups_get

#------------------------------------------------------------------------------#
#
#                /$$
#               | $$
#     /$$$$$$  /$$$$$$
#    /$$__  $$|_  $$_/
#   | $$  \ $$  | $$
#   | $$  | $$  | $$ /$$
#   |  $$$$$$$  |  $$$$/
#    \____  $$   \___/
#    /$$  \ $$
#   |  $$$$$$/
#    \______/
#
#  This file is part of the 'rstudio/gt' project.
#
#  Copyright (c) 2018-2024 gt authors
#
#  For full copyright and license information, please look at
#  https://gt.rstudio.com/LICENSE.html
#
#------------------------------------------------------------------------------#


.dt_row_groups_key <- "_row_groups"

dt_row_groups_get <- function(data) {
  dt__get(data, .dt_row_groups_key)
}

dt_row_groups_set <- function(data, row_groups) {
  dt__set(data, .dt_row_groups_key, row_groups)
}

dt_row_groups_init <- function(data) {

  stub_df <- dt_stub_df_get(data = data)

  if (all(is.na(stub_df[["group_id"]]))) {
    row_groups <- character(0L)
  } else {
    row_groups <- unique(stub_df[["group_id"]])
  }

  dt_row_groups_set(data = data, row_groups = row_groups)
}
rstudio/gt documentation built on Nov. 2, 2024, 5:53 p.m.