size_of: Get the serialization size of an object

View source: R/size_of.R

size_ofR Documentation

Get the serialization size of an object

Description

Get the serialization size of an object

Usage

size_of(object)

Arguments

object

An R object whose size should be calculated.

Value

The number of bytes the object consumes if serialized. The value inherits class object_size.

Examples

## Size of integer vector 1, 2, ..., 1000
size_of(seq(from = 1L, to = 1000L, by = 1L))

## Size of ALTREP representation of integer vector 1, 2, ..., 1000
size_of(1:1000)


## Functions created locally carry the weight of other objects
## in the same environment as the function
make_fcn <- function(n) {
  cargo <- sample.int(n)
  a <- 42
  function() a
}

## Size of teeny 'cargo' + 'a' + a little bit more
size_of(make_fcn(0))

## Size of huge 'cargo' + 'a' + a little bit more
size_of(make_fcn(1e6))




HenrikBengtsson/environments documentation built on Jan. 15, 2025, 12:58 a.m.