R/obj_size.R

Defines functions obj_size

Documented in obj_size

#' Print Human readable object size
#' @param obj Object to be inspected
#' @export
obj_size <- function(obj = NULL) {
  if (is.null(obj)) {
    stop("Object is empty")
  }
  unit_str <- "B"
  obj_s <- base::as.numeric(utils::object.size(obj))
  if (obj_s > 1024) {
    unit_str <- "KiB"
  }
  if (obj_s > 1024 * 1024) {
    unit_str <- "MiB"
  }
  if (obj_s > 1024 * 1024 * 1024) {
    unit_str <- "GiB"
  }
  base::print(
    base::format(
      utils::object.size(obj),
      units = unit_str, standard = "IEC", digits = 1L
    )
  )
}
luciorq/luciolib documentation built on Dec. 18, 2020, 11:43 a.m.