R/dt_transforms.R

Defines functions dt_transforms_add dt_transforms_init dt_transforms_set dt_transforms_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_transforms_key <- "_transforms"

dt_transforms_get <- function(data) {
  dt__get(data, .dt_transforms_key)
}

dt_transforms_set <- function(data, transforms) {
  dt__set(data, .dt_transforms_key, transforms)
}

dt_transforms_init <- function(data) {
  dt_transforms_set(data = data, transforms = list())
}

dt_transforms_add <- function(data, loc, fn) {

  existing_transforms <- dt_transforms_get(data = data)
  resolved <- resolve_location(loc = loc, data = data)

  added_transform <- list(resolved = resolved, fn = fn)

  transforms <-
    c(
      existing_transforms,
      list(added_transform)
    )

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