From 3e3faea9cbe1e243bd8333c68eea50cd8c19ef8c Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 17 Mar 2022 15:11:47 -0500 Subject: [PATCH] Use lobstr instead of pryr --- DESCRIPTION | 2 +- vectors.Rmd | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b4b32f9..8ce7e71 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,12 +18,12 @@ Imports: janitor, Lahman, leaflet, + lobstr, maps, microbenchmark, nycflights13, openxlsx, palmerpenguins, - pryr, readxl, stringr, tidyverse, diff --git a/vectors.Rmd b/vectors.Rmd index a97eba3..299dfec 100644 --- a/vectors.Rmd +++ b/vectors.Rmd @@ -137,18 +137,18 @@ You've already learned a lot about working with strings in [strings]. Here I wanted to mention one important feature of the underlying string implementation: R uses a global string pool. This means that each unique string is only stored in memory once, and every use of the string points to that representation. This reduces the amount of memory needed by duplicated strings. -You can see this behaviour in practice with `pryr::object_size()`: +You can see this behaviour in practice with `lobstr::obj_size()`: ```{r} x <- "This is a reasonably long string." -pryr::object_size(x) +lobstr::obj_size(x) y <- rep(x, 1000) -pryr::object_size(y) +lobstr::obj_size(y) ``` `y` doesn't take up 1,000x as much memory as `x`, because each element of `y` is just a pointer to that same string. -A pointer is 8 bytes, so 1000 pointers to a 152 B string is 8 \* 1000 + 152 = 8.14 kB. +A pointer is 8 bytes, so 1000 pointers to a 152 B string is 8 \* 1000 + 152 = 8,144 B. ### Missing values {#missing-values-vectors}