R/utils.R

Defines functions glueb when unnamed add_class match_arg

match_arg <- function(arg, assert = TRUE) {

  if (is.null(arg)) return(NULL)
  sys_parent <- sys.parent()
  formal_args <- formals(sys.function(sys_parent))
  choices <- eval(formal_args[[as.character(substitute(arg))]],
                  envir = sys.frame(sys_parent))

  if (length(arg) > 1 || identical(arg, choices)) {
    NULL
  } else {
    if (assert) assert_choice(arg, choices)
    arg
  }

}

add_class <- function(obj, class) {

  set_class(obj, union(class, class(obj)))

}

unnamed <- function(...) {

  x <- list(...)
  if (is.null(names(x))) {
    x
  } else {
    x[names(x) == ""]
  }

}

when <- function(x, flag, value) {

  assert_flag(flag)
  if (flag) value else x

}

glueb <- function(..., .envir = parent.frame()) {

  glue(
    ...,
    .open  = "{{",
    .close = "}}",
    .envir = .envir
  )

}
tjpalanca/bulma.R documentation built on Dec. 23, 2021, 10:58 a.m.