R/utils.R

Defines functions compact compare.glue glue_collapse fix_windows_nl yes_no

"%:::%" <- function(p, f) {
  get(f, envir = asNamespace(p))
}

yes_no <- function(x) {
  if (isTRUE(x)) {
    crayon::green(clisymbols::symbol$tick)
  } else {
    crayon::red(clisymbols::symbol$cross)
  }
}

fix_windows_nl <- function(x) {
  gsub("\r\n", "\n", x)
}

glue_collapse <- function(...) {
  if (utils::packageVersion("glue") > "1.2.0") {
    utils::getFromNamespace("glue_collapse", "glue")(...)
  } else {
    utils::getFromNamespace("collapse", "glue")(...)
  }
}

compare.glue <- function(x, y) {
  if (identical(class(y), "character")) {
    class(x) <- NULL
  }
  NextMethod("compare")
}

compact <- function(x) {
  len <- lengths(x)
  x[!len == 0]
}

Try the available package in your browser

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

available documentation built on July 11, 2022, 1:05 a.m.