# NOT RUN {
object.size(letters)
object.size(ls)
format(object.size(library), units = "auto")
sl <- object.size(rep(letters, 1000))
print(sl) ## 209288 bytes
print(sl, units = "auto") ## 204.4 Kb
print(sl, units = "auto", standard = "IEC") ## 204.4 KiB
print(sl, units = "auto", standard = "SI") ## 209.3 kB
(fsl <- sapply(c("Kb", "KB", "KiB"),
function(u) format(sl, units = u)))
stopifnot(identical( ## assert that all three are the same :
unique(substr(as.vector(fsl), 1,5)),
format(round(as.vector(sl)/1024, 1))))
## find the 10 largest objects in the base package
z <- sapply(ls("package:base"), function(x)
object.size(get(x, envir = baseenv())))
if(interactive()) {
as.matrix(rev(sort(z))[1:10])
} else # (more constant over time):
names(rev(sort(z))[1:10])
# }
Run the code above in your browser using DataLab