#' How much memory is presently/maximally used by R?
#'
#' This function is inspired by pryr::mem_used function.
#'
#' @param maximum locical, whether to show the maximum memory that R used.
#' Default is FALSE, which means the memory that R currently used.
#' @import pryr
#' @examples
#' \dontrun{
#' mem_use2()
#' mem_use2(TRUE)
#'
#' x = matrix(1.2, nrow = 10000, ncol = 1000)
#' mem_used2()
#' mem_used2(TRUE)
#'
#' # After removing x, current memory recover but the maximum memory does not.
#' rm(x)
#' mem_used2()
#' mem_used2(TRUE)
#' }
#' @export
mem_used2 = function(maximum = FALSE){
show_bytes = utils::getFromNamespace("show_bytes", ns = "pryr")
node_size = utils::getFromNamespace("node_size", ns = "pryr")
if (maximum){
mem = show_bytes(sum(gc()[, "max used"] * c(node_size(), 8)))
} else {
mem = show_bytes(sum(gc()[, 1] * c(node_size(), 8)))
}
return(mem)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.