R/paint_stub.R

Defines functions paint_stub_template paint_stub.sfg paint_stub.array paint_stub.default paint_stub

#' stub 
#'
#' The stub is the bit after the name in the object title e.g. tibble [row,
#' cols] - stub is the dimensions summary after "tibble"
#' @noRd

paint_stub <- function(object) UseMethod("paint_stub") 

#' @export
paint_stub.default <- function(df) {

  if (is.null(df)) stop("paint_stub got passed NULL")
  if (is_na_value_safely(df)) stop("paint_stub got passed NA")
	if (is_infinite_value_safely(df)) stop("paint_stub got passed an infinite value")

	rows <- NROW(df)
	cols <- NCOL(df)

  if (is.vector(df)) {
	  dims <- paste0("[",rows,"]")
	}
	else {
	  dims <- paste0("[",rows, ", ", cols,"]")
	}
	paint_stub_template(dims)
}

#' @export
paint_stub.array <- function(array) {
	dims <- paste0("[", paste0(dim(array),collapse = ", "), "]")
	paint_stub_template(dims)
}

#' @export
paint_stub.sfg <- function(sfg) {
  size <- utils::capture.output(print(pryr::object_size(sfg)))
	trimmed_size <- gsub("\\s", "", size)
	paint_stub_template(trimmed_size)
}

paint_stub_template <- function(dims) {
	crayon::silver(dims)
}
MilesMcBain/paint documentation built on Dec. 5, 2023, 9:11 a.m.