r-lib/sparsevctrs

have threshold to materialize when subsetting down a lot

Opened this issue · 0 comments

I don't know if I love this idea, but it could be useful

library(sparsevctrs)

# long sparse vector
x_long <- new_sparse_real(c(1, 5, 10), c(1, 5, 10), 10000000000)

altrepr::is_altrep(x_long)
#> [1] TRUE
lobstr::obj_size(x_long)
#> 1.24 kB

# short sparse vector
x_short <- x_long[1:2]

altrepr::is_altrep(x_short)
#> [1] TRUE
lobstr::obj_size(x_short)
#> 1.21 kB

# short dense vector
x_dense <- x_short[]

altrepr::is_altrep(x_dense)
#> [1] FALSE
lobstr::obj_size(x_dense)
#> 64 B

Created on 2024-04-19 with reprex v2.1.0