Display 'data.table' metadata
tables.RdConvenience function for concisely summarizing some metadata of all data.tables in memory (or an optionally specified environment).
Usage
tables(mb=type_size, order.col="NAME", width=80,
env=parent.frame(), silent=FALSE, index=FALSE)Arguments
- mb
a function which accepts a
data.tableand returns its size in bytes. By default,type_size(same asTRUE) provides a fast lower bound by excluding the size of character strings in R's global cache (which may be shared) and excluding the size of list column items (which also may be shared). A column"MB"is included in the output unlessFALSEorNULL.- order.col
Column name (
character) by which to sort the output.- width
integer; number of characters beyond which the output for each of the columnsCOLS,KEY, andINDICESare truncated.- env
An
environment, typically the.GlobalEnvby default, see Details.- silent
logical; should the output be printed?- index
logical; ifTRUE, the columnINDICESis added to indicate the indices assorted with each object, seeindices.
Details
Usually tables() is executed at the prompt, where parent.frame() returns .GlobalEnv. tables() may also be useful inside functions where parent.frame() is the local scope of the function; in such a scenario, simply set it to .GlobalEnv to get the same behaviour as at prompt.
mb = utils::object.size provides a higher and more accurate estimate of size, but may take longer. Its default units="b" is appropriate.
Setting silent=TRUE prints nothing; the metadata is returned as a data.table invisibly whether silent is TRUE or FALSE.
Examples
DT = data.table(A=1:10, B=letters[1:10])
DT2 = data.table(A=1:10000, ColB=10000:1)
setkey(DT,B)
tables()
#> NAME NROW NCOL MB COLS KEY
#> 1: DT 10 2 0 A,B B
#> 2: DT2 10000 2 0 A,ColB [NULL]
#> Total: 0MB using type_size