R/utils.R

Defines functions invert text_col msg

msg <- function(..., startup = FALSE) {
  if (startup) {
    if (!isTRUE(getOption("nflverse.quiet"))) {
      packageStartupMessage(text_col(...))
    }
  } else {
    message(text_col(...))
  }
}

text_col <- function(x) {
  # If RStudio not available, messages already printed in black
  if (!rstudioapi::isAvailable()) {
    return(x)
  }

  if (!rstudioapi::hasFun("getThemeInfo")) {
    return(x)
  }

  theme <- rstudioapi::getThemeInfo()

  if (isTRUE(theme$dark)) crayon::white(x) else crayon::black(x)

}

invert <- function(x) {
  if (length(x) == 0) return()
  stacked <- utils::stack(x)
  tapply(as.character(stacked$ind), stacked$values, list)
}

Try the nflverse package in your browser

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

nflverse documentation built on Aug. 14, 2023, 9:07 a.m.