/stringpool

Understand R's Global String Pool

Primary LanguageC++

stringpool

Lifecycle: experimental

The goal of stringpool is to help developers understand R’s global string pool.

Installation

You can install the development version of stringpool like so:

pak::pak("krlmlr/stringpool")

Example

library(stringpool)

Use stringpool() to get all strings currently known to R as a character vector:

lapply(head(stringpool()), charToRaw)
#> [[1]]
#> raw(0)
#> 
#> [[2]]
#> [1] e3 82 99
#> 
#> [[3]]
#> [1] e3 80 aa
#> 
#> [[4]]
#> [1] e3 80 ae
#> 
#> [[5]]
#> [1] 09
#> 
#> [[6]]
#> [1] 0a

If you need to understand the evolution of the global string table, writing to disk is a good idea.

path1 <- tempfile(fileext = ".txt")
write_stringpool(path1, sep = "=====\n")
fs::file_info(path1)
#> # A tibble: 1 × 18
#>   path             type   size permiss…¹ modification_time   user  group devic…²
#>   <fs::path>       <fct> <fs:> <fs::per> <dttm>              <chr> <chr>   <dbl>
#> 1 …da32838fef0.txt file   390K rw-r--r-- 2023-04-08 13:32:19 kiri… staff  1.68e7
#> # ℹ abbreviated names: ¹​permissions, ²​device_id
#> # ℹ 10 more variables: hard_links <dbl>, special_device_id <dbl>, inode <dbl>,
#> #   block_size <dbl>, blocks <dbl>, flags <int>, generation <dbl>,
#> #   access_time <dttm>, change_time <dttm>, birth_time <dttm>

path2 <- tempfile(fileext = ".txt")
write_stringpool(path2, sep = "=====\n")
fs::file_info(path2)
#> # A tibble: 1 × 18
#>   path             type   size permiss…¹ modification_time   user  group devic…²
#>   <fs::path>       <fct> <fs:> <fs::per> <dttm>              <chr> <chr>   <dbl>
#> 1 …da335e95331.txt file   520K rw-r--r-- 2023-04-08 13:32:19 kiri… staff  1.68e7
#> # ℹ abbreviated names: ¹​permissions, ²​device_id
#> # ℹ 10 more variables: hard_links <dbl>, special_device_id <dbl>, inode <dbl>,
#> #   block_size <dbl>, blocks <dbl>, flags <int>, generation <dbl>,
#> #   access_time <dttm>, change_time <dttm>, birth_time <dttm>