Use lobstr instead of pryr

This commit is contained in:
Hadley Wickham 2022-03-17 15:11:47 -05:00
parent c5291a7a86
commit 3e3faea9cb
2 changed files with 5 additions and 5 deletions

View File

@ -18,12 +18,12 @@ Imports:
janitor,
Lahman,
leaflet,
lobstr,
maps,
microbenchmark,
nycflights13,
openxlsx,
palmerpenguins,
pryr,
readxl,
stringr,
tidyverse,

View File

@ -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}