object_size | R Documentation |
Provides an estimate of the memory that is being used to store R objects.
object_size(...)
## S3 method for class 'object_sizes'
is(x)
## S3 method for class 'object_sizes'
as(x)
## S3 method for class 'object_sizes'
c(..., recursive=FALSE)
## S3 method for class 'object_sizes'
format(x, humanReadable=getOption("humanReadable"),
standard="IEC", units, digits=1, width=NULL, sep=" ",
justify=c("right", "left"), ...)
## S3 method for class 'object_sizes'
print(x, quote=FALSE,
humanReadable=getOption("humanReadable"), standard="IEC", units, digits=1,
width=NULL, sep=" ", justify=c("right", "left"), ...)
... |
|
x |
output from |
quote |
whether or not the result should be printed with surrounding quotes. |
humanReadable |
whether to use the “human readable” format. |
standard , units , digits , width , sep , justify |
passed to
|
recursive |
passed to the |
A numeric vector class c("object_sizes", "numeric")
containing
estimated memory allocation attributable to the objects in bytes.
The base R package utils
provides an object.size
function that
handles a single object. The gdata
package provides a similar
object_size
function that handles multiple objects.
Both the utils
and gdata
implementations store the object size
in bytes, but offer a slightly different user interface for showing the object
size in other formats. The gdata
implementation offers human readable
format similar to ls
, df
or du
shell commands, by calling
humanReadable
directly, calling print
with the argument
humanReadable=TRUE
, or by setting options(humanReadable=TRUE)
.
The object_size
function in the gdata
package used to be called
object.size
, masking the base R function of the same name. This was a
potential source of ambiguity and errors when running scripts, depending on
whether the gdata
package was loaded or not. This was improved in the
3.0.0 release of gdata
by renaming the function to object_size
and in version 3.1.0 when object.size
was removed from the gdata
package.
object.size
in package 'utils' for the base R
implementation,
Memory-limits
for the design limitations on object size,
humanReadable
for human readable format.
object_size(letters)
object_size(ls)
# Find the 10 largest objects in the base package
allObj <- sapply(ls("package:base"), function(x)
object_size(get(x, envir=baseenv())))
(bigObj <- as.object_sizes(rev(sort(allObj))[1:10]))
print(bigObj, humanReadable=TRUE)
as.object_sizes(14567567)
oldopt <- options(humanReadable=TRUE)
(z <- object_size(letters,
c(letters, letters),
rep(letters, 100),
rep(letters, 10000)))
is.object_sizes(z)
as.object_sizes(14567567)
options(oldopt)
# Comparison
# gdata
print(object_size(loadNamespace), humanReadable=TRUE)
print(bigObj, humanReadable=TRUE)
# utils
print(utils::object.size(loadNamespace), units="auto")
sapply(bigObj, utils:::format.object_size, units="auto")
# ll
ll("package:base")[order(-ll("package:base")$KB)[1:10],]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.