R/utils.R

#' Timestamp 
#' 
#' As a character vector in ISO-8601 format.
#' 
#' @noRd 
Timestamp <- function() {
  format(Sys.time(), "%FT%T")
}

#' Create random strings
#' 
#' @param len string length.
#' @noRd
random_string <- function(len = 16) {
  values <- c(letters, LETTERS, 0:9)
  paste(sample(values, len, replace = TRUE), collapse = "")
}

#' Wraps message condition of R
#' 
#' @param ... arguments to be passed to \code{paste} call.
#' @noRd
event_message <- function(...) {
  .event_condition(message, ...)
}

event_stop <- function(...) {
  # TODO match call for stop
  .event_condition(stop, ...)
}

.event_condition <- function(cond, ...) {
  dots <- list(...)
  ## make cond from NSE to character for parsing..
  cond <- as.character(substitute(cond))
  if (getOption("SHINYNOTES.VERBOSE")) {
    text <- paste("[shinyNotes]", dots)
    eval(parse(text = sprintf("%s(\"%s\")", cond, text, call)))
  } else {
    invisible()
  }
}
strboul/shinyNotes documentation built on June 2, 2019, 10:56 p.m.