library(lazyarray)
Create a blank array and assign R object
# Sample data (~24 MB)
rnorm(3e6); dim(x) <- c(10, 100, 100, 30)
x <-
# Save array to a path
tempfile()
path <- create_lazyarray(path, 'double', dim(x), multipart = TRUE)
arr <- x arr[] <-
Load existing array
# Load existing array
load_lazyarray(path) arr <-
The loaded array is read-only by default. However, they can be set writable.
# Make loaded array writable
$make_writable()
arr$can_write
arr#> [1] TRUE
$make_writable()
arrdimnames(arr) <- list(
A = 1:10,
B = 1:100,
C = 1:100,
D = 1:30
)
# Subset/read array
arr[]
y1 <- arr[,,,3]
y2 <-
# Write to slice of data, writing to slices along the
# last dimension is optimized
1] <- seq_len(1e5) arr[,,,
subset(arr, A ~ A <= 2, B ~ B == 10)
sub <-dim(sub)
#> [1] 2 1 100 30
Data created via lazyarray
does not remove automatically. You need to finalize array by yourself. This is because multiple lazy array instances might point to a same dataset. If one of the object is garbage collected, you might not want to remove the data on hard drive as this will invalidate the other instances. To manually remove data, use
$remove_data()
arr#> [1] TRUE