R/show.token.R

Defines functions reveal print.token

Documented in print.token reveal

#' Print method for token
#'
#' @return NULL
#' @param x an object used to select a method.
#' @param ... further arguments passed to or from other methods
#' @param reveal Should the token be revealed
#' @export
#'
#' @examples
#' x = "asdf"
#' class(x) = "token"
#' print(x)
#' attr(x, "timestamp") = Sys.time()
#' print(x)
#'
#' print(x, reveal = TRUE)
#' @method print token
print.token = function(x, reveal = FALSE, ...) {
  ts = attr(x, "timestamp")
  if (!is.null(ts)) {
    cat(paste0("Token Retrieved at: ", ts, "\n"))
  }
  if (reveal) {
    print(as.character(x), ...)
  } else {
    cat("<hidden token>")
  }
  invisible(x)
}

#' @export
#' @rdname print.token
reveal = function(x, ...) {
  print(x, reveal = TRUE, ...)
}

Try the mscstts package in your browser

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

mscstts documentation built on June 10, 2022, 5:11 p.m.