R/theme.R

Defines functions validateTheme

validateTheme <- function(theme, call = parent.frame()) {
  if (is.null(theme)) theme <- omopViewerThemes$default
  keys <- names(omopViewerThemes)
  msg <- paste0(
    "theme must be a 'bslib::bs_theme()' character or a choice between: ",
    glue::glue_collapse(keys, sep = ", ", last = " or "), "."
  )
  omopgenerics::assertCharacter(theme, length = 1, call = call)
  if (theme %in% keys) {
    theme <- omopViewerThemes[[theme]]
  } else {
    isTheme <- tryCatch(
      bslib::is_bs_theme(rlang::eval_tidy(rlang::parse_expr(theme))),
      error = function(e) FALSE
    )
    if (!isTheme) {
      cli::cli_abort(message = msg, call = call)
    }
  }
  return(theme)
}

Try the OmopViewer package in your browser

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

OmopViewer documentation built on April 15, 2025, 5:08 p.m.