R/cached.R

Defines functions print.cached cached.default cached

Documented in cached cached.default print.cached

#' cached
#'
#' subclass for working with cached objects: `path`, `dir`, `file`, `name`,
#' `ext`, etc.
#'
#' @param x object to subclass
#'
#' @details
#'
#' These are essentially used for providing special methods for cache objects vs
#' their **fs** counterparts.
#'
#' The biggest difference is *cached* ext vs a fs extension
#'
#' @examples
#'
#'   x <- path('cache') %>% cached()
#'   print(x)   # A cache path(s) at:
#'
#'
#' @export

cached <- function(x, ...) UseMethod('cached')

#' @rdname cached
#' @export
cached.default <- function(x,...)
  add_subclass( as.character(x), 'cached')

#' @rdname cached
#' @export
print.cached <- function(x, ...) {
  cat('A cached', class(x)[[2]] %>% squote(), ': ' )
  x %>%
    unclass() %>%
    crayon::red() %>%
    # squote() %>%
    collapse_comma() %>%
    cat()

  invisible(x)
}
decisionpatterns/cache documentation built on June 15, 2020, 9:35 p.m.