knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(lazyarray)
Create a blank array and assign R object
# Sample data (~24 MB) x <- rnorm(3e6); dim(x) <- c(10, 100, 100, 30) # Save array to a path path <- tempfile() arr <- lazyarray(path, dim = dim(x), storage_format = 'double') arr[] <- x
Load existing array
# Load existing array arr <- lazyarray(path)
To protect array from further changes, make it read-only.
arr$make_readonly() arr$can_write
To make a read-only array writable:
arr$make_writable() arr$can_write
arr$make_writable() dimnames(arr) <- list( A = 1:10, B = 1:100, C = 1:100, D = 1:30 )
# Subset/read array y1 <- arr[] y2 <- arr[,,,3] # Write to slice of data, writing to slices along the # last dimension is optimized arr[,,,1] <- seq_len(1e5)
sub <- subset(arr, A ~ A <= 2, B ~ B == 10) dim(sub)
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
arr$remove_data()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.