R/utils.R

Defines functions column_from_aes all_aesthetics filter_agg_exprs filter_col_exprs_by_cta col_expr_has_cta

col_expr_has_cta <-
  function(col_expr, cta_name = c("identity", "bin", "count", "avg")) {
    cta_name <- match.arg(cta_name)

    cta_name_to_class_mapping <- list(
      identity = new_sgl_cta_identity(),
      bin = new_sgl_cta_bin(),
      count = new_sgl_cta_count(),
      avg = new_sgl_cta_avg()
    )

    identical(cta_name_to_class_mapping[[cta_name]], col_expr$cta)
  }

filter_col_exprs_by_cta <-
  function(col_exprs, cta_name = c("identity", "bin", "count", "avg")) {
    cta_name <- match.arg(cta_name)

    purrr::keep(
      col_exprs,
      ~ col_expr_has_cta(.x, cta_name)
    )
  }

filter_agg_exprs <- function(col_exprs) {
  col_exprs[
    purrr::map_lgl(col_exprs, ~ (is_aggregation(.$cta)))
  ]
}

all_aesthetics <- function(rgs) {
  layer_aesthetics <- purrr::map(
    rgs$layers,
    ~ names(.$aes_mappings)
  )
  unique(unlist(layer_aesthetics))
}

column_from_aes <- function(layer, df, aes) {
  col_name_from_aes <- layer$aes_mappings[[aes]]$column
  df[[col_name_from_aes]]
}

Try the rsgl package in your browser

Any scripts or data that you put into this service are public.

rsgl documentation built on June 9, 2026, 1:07 a.m.