I've been using the
pryr library to report memory usage of objects.
Generally I need to collect both the raw numeric value in bytes, and also a "human readable" string of the size.
This used to work for me:
# Size of an object utilizing builtin R function obj_size <- object.size(my_obj) obj_size_raw <- as.numeric(obj_size) # 7806621952 obj_size_str <- format(obj_size, "auto") # '7.3 GiB' # Size of an object using pryr obj_size <- pryr::object_size(my_obj) obj_size_raw <- as.numeric(obj_size) # 7806620144 obj_size_str <- capture.output(obj_size) # '7,806,620,144 B' # Total memory utilized using pryr total_size <- pryr::mem_used() total_size_raw <- as.numeric(total_size) # 8985272040 total_size_str <- capture.output(total_size) # '8.99 GB'
I'm not sure exactly since when or from which version, but the
capture.output for the pryr's object size stopped returning human readable strings. For example, instead of returning
7.3 GiB, it returns now
I've read in pryr's GitHub repository thath it was superseded by lobstr for the matters of object size comparison. So, I see that it has
lobstr::mem_used() functions, both returning an object of the class
lobstr_bytes. I tried using
format()base functions to create a "human readable" string from the
lobstr_bytes objects, but it did not work.
What is the best way to create a "human readable" string for the