This function is modified copy of the utils:::format.object_size function which is not exported. The main difference is that it returns values.
format_object_size(x, units = "b", standard = "auto", digits = 1L, ...)
a number
a unit
a standard
number of digits
anything else