Home > Back-end >  How do I interpret the units from object.size?
How do I interpret the units from object.size?

Time:09-13

The documentation of object.size suggests that it can accept either "MB" or "Mb" as arguments to format. I understand that "B" is the abbreviation for byte and "b" for bit. However, when I call the format function with these two inputs, I get the same result. And this result has units of "b".

Is it respecting the distinction between bits and bytes? Or should I interpret all results as bytes despite the lower case "b"?

x <- runif(1e6)
format(object.size(x), "Mb")
#> [1] "7.6 Mb"
format(object.size(x), "MB")
#> [1] "7.6 Mb"

Created on 2022-09-12 by the reprex package (v2.0.1)

CodePudding user response:

If you check the formatting part in the documentation you'll see that the default formatting is done in bytes.

the byte-size unit standard to be used. A character string, possibly abbreviated from "legacy", "IEC", "SI" and "auto". See ‘Formatting and printing object sizes’ for details.

Also if you try:

> print(object.size(x))
8000048 bytes

where this equals roughly to 7.6 MB.

  •  Tags:  
  • r
  • Related