#' 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
)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.