R/utils.R

Defines functions random_id_generator interlace_dividers get_inverted_class verify_value_allowed

# Verify that given variable is in the list of allowed values.
verify_value_allowed <- function(variable, values) {
  var <- get(variable, envir = parent.frame())
  if (!(var %in% values)){
    warning(paste(paste0("'", variable, "'"),
                  "argument should be one of:",
                  paste0("'", values, "'", collapse = ", ")))
  }
}

# Changes logical inverted value to CSS class string.
get_inverted_class <- function(inverted) {
  ifelse(inverted, "inverted", "")
}

# Interlace elements with dividers between each pair of elements.
interlace_dividers <- function(elements) {
  dividers <- lapply(1:length(elements), function(i) shiny::tags$div(class = "divider"))
  utils::head(c(rbind(elements, dividers)), -1) # Skips last divider with head.
}

# Random ID generator
random_id_generator <- function(values = 0:9, id_length = 30) {
  paste0(sample(values, id_length, TRUE), collapse = "")
}

Try the semantic.dashboard package in your browser

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

semantic.dashboard documentation built on Jan. 16, 2021, 5:28 p.m.