EVOLUTION-MANAGER
Edit File: object.size.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Report the Space Allocated for an Object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for object.size {utils}"><tr><td>object.size {utils}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Report the Space Allocated for an Object</h2> <h3>Description</h3> <p>Provides an estimate of the memory that is being used to store an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object. </p> <h3>Usage</h3> <pre> object.size(x) ## S3 method for class 'object_size' format(x, units = "b", standard = "auto", digits = 1L, ...) ## S3 method for class 'object_size' print(x, quote = FALSE, units = "b", standard = "auto", digits = 1L, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object.</p> </td></tr> <tr valign="top"><td><code>quote</code></td> <td> <p>logical, indicating whether or not the result should be printed with surrounding quotes.</p> </td></tr> <tr valign="top"><td><code>units</code></td> <td> <p>the units to be used in formatting and printing the size. Allowed values for the different <code>standard</code>s are </p> <dl> <dt><code>standard = "legacy"</code>:</dt><dd> <p><code>"b"</code>, <code>"Kb"</code>, <code>"Mb"</code>, <code>"Gb"</code>, <code>"Tb"</code>, <code>"Pb"</code>, <code>"B"</code>, <code>"KB"</code>, <code>"MB"</code>, <code>"GB"</code>, <code>"TB"</code> and <code>"PB"</code>.</p> </dd> <dt><code>standard = "IEC"</code>:</dt><dd> <p><code>"B"</code>, <code>"KiB"</code>, <code>"MiB"</code>, <code>"GiB"</code>, <code>"TiB"</code>, <code>"PiB"</code>, <code>"EiB"</code>, <code>"ZiB"</code> and <code>"YiB"</code>.</p> </dd> <dt><code>standard = "SI"</code>:</dt><dd> <p><code>"B"</code>, <code>"kB"</code>, <code>"MB"</code>, <code>"GB"</code>, <code>"TB"</code>, <code>"PB"</code>, <code>"EB"</code>, <code>"ZB"</code> and <code>"YB"</code>.</p> </dd> </dl> <p>For all standards, <code>unit = "auto"</code> is also allowed. If <code>standard = "auto"</code>, any of the "legacy" and <acronym><span class="acronym">IEC</span></acronym> units are allowed. See ‘Formatting and printing object sizes’ for details.</p> </td></tr> <tr valign="top"><td><code>standard</code></td> <td> <p>the byte-size unit standard to be used. A character string, possibly abbreviated from <code>"legacy"</code>, <code>"IEC"</code>, <code>"SI"</code> and <code>"auto"</code>. See ‘Formatting and printing object sizes’ for details.</p> </td></tr> <tr valign="top"><td><code>digits</code></td> <td> <p>the number of digits after the decimal point, passed to <code><a href="../../base/html/Round.html">round</a></code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments to be passed to or from other methods.</p> </td></tr> </table> <h3>Details</h3> <p>Exactly which parts of the memory allocation should be attributed to which object is not clear-cut. This function merely provides a rough indication: it should be reasonably accurate for atomic vectors, but does not detect if elements of a list are shared, for example. (Sharing amongst elements of a character vector is taken into account, but not that between character vectors in a single object.) </p> <p>The calculation is of the size of the object, and excludes the space needed to store its name in the symbol table. </p> <p>Associated space (e.g., the environment of a function and what the pointer in a <code>EXTPTRSXP</code> points to) is not included in the calculation. </p> <p>Object sizes are larger on 64-bit builds than 32-bit ones, but will very likely be the same on different platforms with the same word length and pointer size. </p> <p>Sizes of objects using a compact internal representation may be over-estimated. </p> <h3>Value</h3> <p>An object of class <code>"object_size"</code> with a length-one double value, an estimate of the memory allocation attributable to the object in bytes. </p> <h3>Formatting and printing object sizes</h3> <p>Object sizes can be formatted using byte-size units from <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>'s legacy standard, the <acronym><span class="acronym">IEC</span></acronym> standard, or the <acronym><span class="acronym">SI</span></acronym> standard. As illustrated by below tables, the legacy and <acronym><span class="acronym">IEC</span></acronym> standards use <em>binary</em> units (multiples of 1024), whereas the SI standard uses <em>decimal</em> units (multiples of 1000). </p> <p>For methods <code>format</code> and <code>print</code>, argument <code>standard</code> specifies which standard to use and argument <code>units</code> specifies which byte-size unit to use. <code>units = "auto"</code> chooses the largest units in which the result is one or more (before rounding). Byte sizes are rounded to <code>digits</code> decimal places. <code>standard = "auto"</code> chooses the standard based on <code>units</code>, if possible, otherwise, the legacy standard is used. </p> <p>Summary of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>'s legacy and <acronym><span class="acronym">IEC</span></acronym> units: </p> <table summary="Rd table"> <tr> <td style="text-align: left;"> <b>object size</b> </td><td style="text-align: left;"><b>legacy</b> </td><td style="text-align: left;"><b>IEC</b></td> </tr> <tr> <td style="text-align: left;"> 1 </td><td style="text-align: left;"> 1 bytes </td><td style="text-align: left;"> 1 B </td> </tr> <tr> <td style="text-align: left;"> 1024 </td><td style="text-align: left;"> 1 Kb </td><td style="text-align: left;"> 1 KiB </td> </tr> <tr> <td style="text-align: left;"> 1024^2 </td><td style="text-align: left;"> 1 Mb </td><td style="text-align: left;"> 1 MiB </td> </tr> <tr> <td style="text-align: left;"> 1024^3 </td><td style="text-align: left;"> 1 Gb </td><td style="text-align: left;"> 1 GiB </td> </tr> <tr> <td style="text-align: left;"> 1024^4 </td><td style="text-align: left;"> 1 Tb </td><td style="text-align: left;"> 1 TiB </td> </tr> <tr> <td style="text-align: left;"> 1024^5 </td><td style="text-align: left;"> 1 Pb </td><td style="text-align: left;"> 1 PiB </td> </tr> <tr> <td style="text-align: left;"> 1024^6 </td><td style="text-align: left;"> </td><td style="text-align: left;"> 1 EiB </td> </tr> <tr> <td style="text-align: left;"> 1024^7 </td><td style="text-align: left;"> </td><td style="text-align: left;"> 1 ZiB </td> </tr> <tr> <td style="text-align: left;"> 1024^8 </td><td style="text-align: left;"> </td><td style="text-align: left;"> 1 YiB </td> </tr> <tr> <td style="text-align: left;"> </td> </tr> </table> <p>Summary of <acronym><span class="acronym">SI</span></acronym> units: </p> <table summary="Rd table"> <tr> <td style="text-align: left;"> <b>object size</b> </td><td style="text-align: left;"> <b>SI</b> </td> </tr> <tr> <td style="text-align: left;"> 1 </td><td style="text-align: left;"> 1 B </td> </tr> <tr> <td style="text-align: left;"> 1000 </td><td style="text-align: left;"> 1 kB </td> </tr> <tr> <td style="text-align: left;"> 1000^2 </td><td style="text-align: left;"> 1 MB </td> </tr> <tr> <td style="text-align: left;"> 1000^3 </td><td style="text-align: left;"> 1 GB </td> </tr> <tr> <td style="text-align: left;"> 1000^4 </td><td style="text-align: left;"> 1 TB </td> </tr> <tr> <td style="text-align: left;"> 1000^5 </td><td style="text-align: left;"> 1 PB </td> </tr> <tr> <td style="text-align: left;"> 1000^6 </td><td style="text-align: left;"> 1 EB </td> </tr> <tr> <td style="text-align: left;"> 1000^7 </td><td style="text-align: left;"> 1 ZB </td> </tr> <tr> <td style="text-align: left;"> 1000^8 </td><td style="text-align: left;"> 1 YB </td> </tr> <tr> <td style="text-align: left;"> </td> </tr> </table> <h3>Author(s)</h3> <p>R Core; Henrik Bengtsson for the non-legacy <code>standard</code>s.</p> <h3>References</h3> <p>The wikipedia page, <a href="https://en.wikipedia.org/wiki/Binary_prefix">https://en.wikipedia.org/wiki/Binary_prefix</a>, is extensive on the different standards, usages and their history. </p> <h3>See Also</h3> <p><code><a href="../../base/html/Memory-limits.html">Memory-limits</a></code> for the design limitations on object size. </p> <h3>Examples</h3> <pre> 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]) </pre> <hr /><div style="text-align: center;">[Package <em>utils</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>